Home > Article > Backend Development > How to close the database in php?
php method to close the database: 1. You can use [mysql_close()] to close the database connection; 2. You can set the connection resource parameters to close the specified database connection, the code is [$link = mysql_connect($ host) mysql_close($link)].
php method to close the database:
After the database operation is completed, you can use mysql_close to close the database connection. By default, when PHP is executed, the database connection will be automatically closed.
mysql_close();
Although PHP will automatically close the database connection, which generally meets the needs, but in the case of relatively high performance requirements, the database connection can be closed as soon as possible after the database operation is completed to save resources and improve performance.
When there are multiple database connections, you can set the connection resource parameters to close the specified database connection.
$link = mysql_connect($host, $user, $pass); mysql_close($link);
Code:
<?php //连接数据库 mysql_connect('127.0.0.1', 'code1', ''); mysql_select_db('code1'); mysql_query("set names 'utf8'"); //在这里关闭数据库连接 ?php>
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of How to close the database in php?. For more information, please follow other related articles on the PHP Chinese website!