doudou7361 2011-09-14 14:12
浏览 103

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 are 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.

  • 写回答

1条回答 默认 最新

  • dongquming3255 2011-09-15 08:29
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集