Home >Backend Development >PHP Problem >How to close database connection in php?

How to close database connection in php?

青灯夜游
青灯夜游Original
2020-09-27 16:26:263487browse

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.

How to close database connection in php?

## 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.

Syntax

mysqli_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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn