有什么理由让我在查询之后或脚本结束时关闭连接吗?
Is there any reason why I should close the connection after a query or at the end of the script?
做/不做有什么好处?
连接(如果不是持久的) 总是在脚本结束时关闭,所以,理论上,你不会需要自己关闭.
The connection (if not persistent) is always closed at the end of the script, so, in theory, you don't need to close it yourself.
不过,如果您的 PHP 脚本需要大量时间来执行,那么当您不再需要对数据库执行任何请求时关闭连接是个好主意——至少,如果长时间的计算是在之后完成的查询.
Still, if your PHP script takes lots of time to execute, it's a good idea to close the connection when you don't have to do any request to the database anymore -- at least, if the long calculations are done after the queries.
如果您的应用程序部署在共享主机上,则尤其如此:您的用户帐户通常只能同时打开几个连接.(在共享主机上,同时打开的连接数量可能很少;在私人服务器上通常更大).
This is especially true if your application is deployed on a shared hosting : your user account can generally only have a few connections opened at the same time. (That number of simultaneous opened connections can be pretty small on shared hosting ; it's generally bigger on private servers).
我们经常不关闭自己的联系的原因是:
The reason we often don't close connections ourselfves is :
这篇关于为什么要使用 mysqli_close()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
mysql 中的 store_result() 和 get_result() 返回 falsestore_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
调用未定义的函数 mysqli_result::num_rows()Call to undefined function mysqli_result::num_rows()(调用未定义的函数 mysqli_result::num_rows())
PHP 准备好的语句问题PHP Prepared Statement Problems(PHP 准备好的语句问题)
mysqli_fetch_array 只返回一个结果mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一个结果)
PHP MySQLi 多次插入PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
如何确保 MySQL 中的值在 PHP 中保持其类型?How do I make sure that values from MySQL keep their type in PHP?(如何确保 MySQL 中的值在 PHP 中保持其类型?)