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

How to close the database in php?

coldplay.xixi
coldplay.xixiOriginal
2020-07-22 10:17:224028browse

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)].

How to close the database in php?

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(&#39;127.0.0.1&#39;, &#39;code1&#39;, &#39;&#39;);
mysql_select_db(&#39;code1&#39;);
mysql_query("set names &#39;utf8&#39;");
//在这里关闭数据库连接
?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!

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

Related articles

See more