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

How to close mysql connection in php

王林
Release: 2023-03-02 19:12:01
Original
3220 people have browsed it

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);
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template