简体   繁体   English

大数据集哪个更快? mysql、mysqli 或 PDO?

[英]Which is faster for Large Data Sets? mysql, mysqli or PDO?

I am working with a rather large database of information now and some queries return quite a hefty amount of information.我现在正在处理一个相当大的信息数据库,一些查询返回了大量的信息。 From what I have read, foreach() is quicker than using while() loops with larger arrays, but that can't be used with mysql functions.根据我的阅读,foreach() 比使用带有更大 arrays 的 while() 循环更快,但不能与 mysql 函数一起使用。

So as a general question, which of the 3 is faster for large databases which feth 1000s of rows with quite a lot of data?所以作为一个普遍的问题,对于包含大量数据的 1000 行的大型数据库,这 3 个中哪一个更快? mysql, mysqli or PDO? mysql、mysqli 或 PDO?

Thanks!谢谢!

mysql shouldn't be used since it's outdated and has been superseded by mysqli . mysql不应使用,因为它已过时并已被mysqli取代。 As for the differences between mysqli and PDO , consider these:至于mysqliPDO之间的区别,请考虑以下几点:

Reasons to use mysqli使用mysqli的理由

  • Should be slightly faster.应该稍微快一点。
  • Easier, especially if you're familiar with the mysql extension, since it is quite similar.更容易,特别是如果您熟悉mysql扩展,因为它非常相似。

Reasons to use PDO使用PDO的理由

  • Much easier to transition to other databases.更容易过渡到其他数据库。
  • More features (eg. named parameters in prepared statements, object mapping).更多功能(例如,准备好的语句中的命名参数,object 映射)。

If you use the Zend_Db class as part of Zend Framework, you can easily switch between mysqli and PDO.如果您使用 Zend_Db class 作为 Zend 框架的一部分,您可以轻松地在 mysqli 和 PDO 之间切换。 Zend_Db is an extra abstraction layer. Zend_Db 是一个额外的抽象层。 To switch underlying libraries you only need to change 1 parameter.要切换底层库,您只需更改 1 个参数。 That's all.就这样。

This way you can write your code once, and benchmark yourself.这样您就可以编写一次代码,然后自己进行基准测试。

MySQLi and PDO will give similar performances, but I believe that MySQLi will be faster than PDO as PDO is more of just a wrapper for it. MySQLi and PDO will give similar performances, but I believe that MySQLi will be faster than PDO as PDO is more of just a wrapper for it. because PDO tailors to multiple databases, where as MySQLi tailors to one.因为 PDO 适合多个数据库,而 MySQLi 适合一个。 But that can be where PDO has an advantage over MySQLi as well.但这也可能是 PDO 优于 MySQLi 的地方。

The original MySQL is outdated by MySQLi.原来的 MySQL 被 MySQLi 过时了。

For benchmarks: http://jnrbsn.com/2010/06/mysqli-vs-pdo-benchmarks基准测试: http://jnrbsn.com/2010/06/mysqli-vs-pdo-benchmarks

I don't expect the database interface to be the bottleneck.我不希望数据库接口成为瓶颈。 I expect the actual database to be the bottleneck.我希望实际的数据库成为瓶颈。

Be sure to understand indexing, InnoDB vs MyISAM, database normalization / denormalization, "EXPLAIN" queries, and prepared queries (both server-side and client-side).请务必了解索引、InnoDB 与 MyISAM、数据库规范化/非规范化、“EXPLAIN”查询和准备好的查询(服务器端和客户端)。 THESE are the issues that affect performance, not the choice of mysqli vs pdo.这些是影响性能的问题,而不是 mysqli 与 pdo 的选择。

Its kinda like saying, which bicycle will be faster in a race?有点像说,哪辆自行车在比赛中跑得更快? Well... the bike doesn't really matter that much, its the person who is riding the bike that makes the difference.嗯……自行车并不重要,重要的是骑自行车的人。 Similarly, it doesn't really matter which database layer you use.同样,您使用哪个数据库层并不重要。 What matters is how much you have tuned your query and tweaked your database.重要的是您对查询和数据库进行了多少调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM