Current Location: Home> Function Categories> mysql_close

mysql_close

Close non-persistent MySQL connection.
Name:mysql_close
Category:Uncategorized
Programming Language:php
One-line Description:Close the previously opened MySQL connection

Function name: mysql_close()

Applicable version: PHP 5.5.0 - PHP 5.6.x, PHP 7

Function Description: The mysql_close() function is used to close a previously opened MySQL connection.

Syntax: bool mysql_close ( resource $link_identifier = ? )

parameter:

  • link_identifier (optional): MySQL connection identifier. If this parameter is not provided, the most recently opened connection is used by default.

Return value: Return true if the connection is successfully closed. If the connection is closed, false is returned.

Example:

 <?php // 打开数据库连接$link = mysql_connect('localhost', 'username', 'password'); if (!$link) { die('数据库连接失败: ' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db('mydatabase', $link); if (!$db_selected) { die ('无法使用数据库: ' . mysql_error()); } // 执行数据库操作... // 关闭连接if (mysql_close($link)) { echo '数据库连接已成功关闭。'; } else { echo '无法关闭数据库连接。'; } ?>

Notes:

  1. After PHP 5.5.0, the mysql extension has been deprecated and is no longer recommended. It is recommended to use mysqli or PDO extension instead.
  2. Before closing the connection with the mysql_close() function, make sure that all database operations are completed, otherwise the unfinished operations may be terminated.
Similar Functions
Popular Articles