Home  >  Article  >  Backend Development  >  How to close mysql connection in php?

How to close mysql connection in php?

coldplay.xixi
coldplay.xixiOriginal
2020-07-13 15:32:264231browse

php method to close the mysql connection: 1. Use [mysql_close()] to close the database connection, which will automatically close; 2. Set the connection resource parameters to close the specified database connection, the code is [$link = mysql_connect($host, $user, $pass】.

How to close mysql connection in php?

php method to close mysql connection:

1 . When 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();

2. Although PHP will automatically close Database connections generally meet the needs, but in cases where performance requirements are relatively high, the database connections can be closed as soon as possible after the database operation is completed to save resources and improve performance.

When there are multiple In the case of a database connection, you can set the connection resource parameters to close the specified database connection.

$link = mysql_connect($host, $user, $pass);
mysql_close($link);

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to close mysql 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