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

时间:2022-04-06 07:17:32

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

在通过互联网进行一项研究之后(在*上) - 我仍然在努力决定哪种方法最适合我学习/使用并在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.

我理解使用DAO处理数据库时使用直接在应用程序文件中分散的直接mysql_ *函数的一些优点。

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?!?

当谈到MDB2与PDO之间的决定时 - 有一点支持PDO的事实是,它不会像mysql_ *那样抽象出直接与mysql api对话的mysql_ *函数。它也是PHP的编译C扩展,因此速度非常快。虽然MDB2(或其他库)是用PHP编写的,但它们需要在运行时进行解析并位于mysql_ *函数之上。那么,就速度而言,PDO赢了?!?

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

在比较DB抽象层而不是本机非抽象的PHP方式时,使用绑定器参数(预备语句)来防止大多数sql注入攻击,以及更容易切换,从而突出了数据库抽象层的安全优势。如果有需要/请求,将来RDBMS类型 - 即使它不常见 - (这些DAO库中还有其他优点和良好的消耗时间特性)。

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

无论如何,我希望有专家可以帮助我决定我应该使用其中一个库,如果是,哪一个是最推荐的?,或者我应该编写自己的DAO库,它将通过我的所有项目和我几年后会有所改善吗?

Thanks.

1 个解决方案

#1


4  

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
  • 我的代码是瓶颈,还是数据库?当您对数据库进行数千次简单查询时,慢速PHP代码就成了问题。当您每个请求只执行几十个查询时,db层的开销可能不会很明显

  • 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.
  • 您是否需要切换到不同的数据库系统?如果您正在为具有明确要求的客户端开展工作,那么您很可能无论如何都要锁定DMBS,并且您不必关心互操作性。

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.

此外,MDB2现在已经很老了。如果我是你,我会使用Doctrines DBAL - 它可以在没有Doctrine本身的情况下使用,并且它位于PDO之上。我不会使用旧的“本机”mysql_ *函数。

#1


4  

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
  • 我的代码是瓶颈,还是数据库?当您对数据库进行数千次简单查询时,慢速PHP代码就成了问题。当您每个请求只执行几十个查询时,db层的开销可能不会很明显

  • 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.
  • 您是否需要切换到不同的数据库系统?如果您正在为具有明确要求的客户端开展工作,那么您很可能无论如何都要锁定DMBS,并且您不必关心互操作性。

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.

此外,MDB2现在已经很老了。如果我是你,我会使用Doctrines DBAL - 它可以在没有Doctrine本身的情况下使用,并且它位于PDO之上。我不会使用旧的“本机”mysql_ *函数。