简体   繁体   English

mysqli_ *或mysql_ *性能?

[英]mysqli_* or mysql_* performance?

In the php.net site, they say that those who use mysql4.1 next to php5 or higher is required to use extremely "MYSQLI_" instead of "MYSQL_." 在php.net网站上,他们说那些在php5或更高版本旁边使用mysql4.1的用户必须使用极端的“ MYSQLI_”而不是“ MYSQL_”。

He wanted to know just one thing, it influences the performance of the site, several problems with site is down due to the database (this on any server). 他只想知道一件事,它会影响站点的性能,由于数据库(在任何服务器上都存在),站点的一些问题已关闭。

Already using various solutions. 已经使用各种解决方案。 For example, CACHE HTML pages. 例如,缓存HTML页面。

But my doubt is really about on MYSQLI_ *, when we use it, she connects to the server and the specified DataBase. 但是我的疑问确实是关于MYSQLI_ *,当我们使用它时,她连接到服务器和指定的数据库。 According to the php.net site is mysql mysqli improved and optimized mysql4.1 +. 根据php.net站点,是对mysql mysqli进行了改进和mysql4.1 +的优化。

I wonder if the traffic with a large MySQLi give better performance to the site. 我想知道大型MySQLi的流量是否能使站点性能更好。

PS.: I know the difference "mysqli" and "mysql", taking into consideration the PHP programming and structuring of MYSQL4.1+ (which has new types of columns). PS .:考虑到PHP编程和MYSQL4.1 +的结构(具有新的列类型),我知道“ mysqli”和“ mysql”的区别。 What I want to know is on multiple connections. 我想知道的是多个连接。

This question is about performance, thanks 这个问题是关于性能的,谢谢

You should read this: 您应该阅读以下内容:

http://blog.secaserver.com/2011/07/php-driver-mysql-mysqli-pdo-mysql/ http://blog.secaserver.com/2011/07/php-driver-mysql-mysqli-pdo-mysql/

mysqli provides better performance and increased functionality and as Evert said, it is especially noticeable if you use mysqlnd. mysqli提供了更好的性能和增强的功能,并且正如Evert所说,如果使用mysqlnd则特别值得注意。

A common comment here at StackOveflow whenever we see code using mysql_* functions should answer your question: 每当我们看到使用mysql_*函数的代码时,在StackOveflow上的常见评论都应该回答您的问题:

Please, don't use mysql_* functions for new code. 请不要对新代码使用mysql_ *函数。 They are no longer maintained and the community has begun the deprecation process . 它们已不再维护,社区已开始弃用过程 See the red box ? 看到红色框了吗? Instead you should learn about prepared statements and use either PDO or MySQLi . 相反,您应该了解准备好的语句,并使用PDOMySQLi If you can't decide, this article will help to choose. 如果您不能决定, 本文将有助于选择。 If you care to learn, here is good PDO tutorial . 如果您想学习,这里有个不错的PDO教程

Yes, MySQLi could give better performance to your site . 是的, MySQLi could give better performance to your site You can use persistent connections , which basically share the same idea of the well known connection pooling , but while the connection pooling is used in java development mostly(usually performed directly by the webserver, eg Apache-Tomcat ), persistent connections are managed by MySQL and PHP . 您可以使用persistent connections ,它们基本上具有与众所周知的connection pooling相同的思想,但是尽管connection pooling主要用于Java开发(通常由Web服务器直接执行,例如Apache-Tomcat ),但是持久性连接由MySQL and PHP管理MySQL and PHP

Besides, MySQLi could help you to secure your queries, by adopting prepared statements . 此外,MySQLi可以通过采用prepared statements来帮助您保护查询。

Mysqli extension provides built-in cleanup handling code, which includes: Mysqli extension提供了内置的清理处理代码,其中包括:

  • Rollback active transactions 回滚活动交易

  • Close prepared statements (always happens with PHP) 关闭准备好的语句(总是在PHP中发生)

  • Close and drop temporary tables 关闭和删除临时表

  • Unlock tables 解锁表

  • Reset session variables 重置会话变量

  • Close handler 关闭处理程序

  • Release locks acquired with GET_LOCK() 使用GET_LOCK()获得的释放锁

All these features could help you to give better performance and security as well. 所有这些功能都可以帮助您提供更好的性能和安全性。

For more informations, you can refer to: 有关更多信息,您可以参考:

http://php.net/manual/en/mysqli.persistconns.php http://php.net/manual/en/mysqli.persistconns.php

The mysql_ functions are no longer maintained and deprecated. 不再维护和弃用mysql_函数。 The mysqli_ functions will perform better, especially if you use the mysqlnd (native driver). mysqli_函数的性能会更好,特别是如果您使用mysqlnd(本机驱动程序)。

Stop using deprecated API's! 停止使用已弃用的API!

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

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