Home >Backend Development >PHP Problem >How to close database connection in php?
In PHP, you can use the mysqli_close() function to close a previously opened database connection. The syntax is "mysqli_close(conn);". The parameter conn is used to specify the MySQL connection to be closed; if the connection is closed successfully, TRUE is returned. , returns FALSE on failure.
## Recommended: "PHP Video Tutorial"
php method to close the database connection
When the database operation is completed, you can use mysql_close to close the database connection. By default, after PHP execution is completed , the database connection will be automatically closed. 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. . mysqli_close() function closes the previously opened database connection. Syntaxmysqli_close(connection);Parameters: connection, required parameter, specifies the MySQL connection to be closed. Return value: TRUE if successful, FALSE if failed.
Example:
$con=mysqli_connect("localhost","my_user","my_password","my_db"); // ....一些 PHP 代码... mysqli_close($con); ?>
Description:
When there are multiple database connections, you can set the connection resources Parameters to close the specified database connection.$link = mysql_connect($host, $user, $pass); // ....一些 PHP 代码... mysql_close($link);
The above is the detailed content of How to close database connection in php?. For more information, please follow other related articles on the PHP Chinese website!