开发者

PHP| PEAR:MDB2 vs PDO vs Native-PHP (Raw)

After doing a sort of a research through out the Internet(And here at Stackoverflow) - I'm still struggling to decide which method is best for me to learn/use and dig more when programming in PHP.

I understand some of the advantaged of using DAO when dealing with DB over using straight mysql_* functions spread out across the application files.

When it comes to decide between MDB2 vs PDO - one thing that shine in favor of PDO is the fact that it doesn't abstract the mysql_* functions it talks directly to the mysql api just as the mysql_* do. It is also a compiled C extension to PHP so is very fast. While MDB2(or other libraries) are written in PHP so they need to be parsed at runtime and sit on top of the mysql_* functions. So, In terms of speed PDO wins?!?

When it comes to compare DB abstraction layer over native-non-abstracted-PHP way shines the security advantages of DB abstraction layers in the way of using binder params(prepared statements) that will prevent most sql injection attacks, plus it is easier to switch RDBMS type in the future if there is a need/request for that - even though it is not that common - (there a开发者_JS百科re other advantages and nice consuming time feature in those DAO libraries).

Anyway I hope that there are experts who can assist me to decide rather I should use one of those libraries and if so, which one is the most recommended?, or should I write my own DAO library that will serve me through all my projects and will get improved with years?.

Thanks.


Ask yourself the questions:

  • Is my code the bottleneck, or is it the database? When you're doing thousands of simple queries against the database, slow php code is a problem. When you're doing only a couple of dozen queries per request, the overhead of the db layer will probably not be noticable
  • Will you ever need to switch to a different db system? If you're doing the work for a client with clear requirements, you're most likely locked to a DMBS anyway, and you don't have to care about interoperability.

Also, MDB2 is pretty aged now. If I were you, I'd use Doctrines DBAL - it can be used without Doctrine itself, and it sits on top of PDO. I would not use the old "native" mysql_* functions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜