开发者

Advantage of using PDOStatement?

what is the difference / advantage of u开发者_Python百科sing PDOStatement instead of regular Mysql?


I'm not sure what you mean by "regular MySQL" but I'm concerned that you might mean string-concatenated queries. So the most direct advantage of using a framework like PDO is to use prepared and parameterized queries. This reduces the risk of SQL injection (but doesn't necessarily eliminate it, so don't think that) and at the same time, depending on the database server, may allow the server to better cache query execution plans to improve performance.

At a higher level, the idea behind using a framework like this is to abstract the actual data access componentry out of the application logic a little more, which is always a worthy goal. Basically, rather than interfacing directly with the database, you'd be interfacing primarily with the data access framework (which in this case can still keep you tightly coupled with the database implementation, so be aware of that) and let it handle the database access. One of the primary benefits to this approach is that, if you change a database implementation (such as move from MySQL to PostgreSQL) then you don't need to change your code. You just use the latter's implementation of PDO as a drop-in replacement for the former's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜