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

How to close mysql connection in php

王林
王林Original
2020-07-21 13:58:343193browse

The method for php to close the mysql connection is: it can be closed through the mysqli_close() function. If successful, it returns TRUE, otherwise it returns FALSE. Function syntax: [mysqli_close(connection)], such as [mysqli_close($link)].

How to close mysql connection in php

Use the mysqli_close() function in php to close the mysql connection.

(Recommended learning: php tutorial)

Function definition and syntax:

mysqli_close() function closes the previously opened database connection. Returns TRUE if successful, FALSE if failed.

mysqli_close(connection);

Parameter description:

  • connection Required. Specifies the MySQL connection to be closed.

Code implementation:

<?php
$link = mysqli_connect(&#39;mysql&#39;,&#39;test&#39;,&#39;123456&#39;,&#39;test&#39;);
if (!$link) {
    die(&#39;连接错误 (&#39;.mysqli_connect_errno().&#39;)&#39;.mysqli_connect_error());
}
echo &#39;成功连接... &#39;.mysqli_get_host_info($link)."\n";
mysqli_close($link);
?>

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