mysqli - 我真的需要做 $result->close();&$mysqli->close();?

2021-12-25 00:00:00 php mysql mysqli

刚开始使用mysqli.如果我在小型网站上使用小型数据集(流量方面),我真的需要一直使用这些吗?

Just started using mysqli. If I'm working with small data sets on small websites (traffic-wise), do I really need to use these all the time?

$result->close(); 
$mysqli->close();

另外,对于在没有框架的情况下进行自定义 PHP 和 MySQL 工作的人来说,mysqli 是与 MySQL 交互的一般首选方式吗?

Also, for someone doing custom PHP and MySQL work without a framework, is mysqli the general preferred way of interacting with MySQL?

推荐答案

PHP 将在脚本结束时关闭所有打开的文件和数据库连接.完成连接后手动执行此操作是一种很好的做法,但如果不这样做也无济于事.如果您有一个将在整个脚本中使用的数据库连接,您也可以将其保持打开状态.

PHP will close all open files and DB connections at the end of the script. It's good practice to do it manually when you are done with the connections, but it's no disaster if you don't. If you have a DB connection that will be used throughout the whole script you can as well leave it open.

+1 对 PDO

相关文章