Home > Article > Backend Development > How to close mysql connection in php
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)].
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('mysql','test','123456','test'); if (!$link) { die('连接错误 ('.mysqli_connect_errno().')'.mysqli_connect_error()); } echo '成功连接... '.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!