PHP mysql_close() Function

Definition and Usage

The mysql_close() function closes a non-persistent MySQL connection.

Syntax

mysql_close(link_identifier)
Parameters Description
link_identifier Required. MySQL connection identifier. If not specified, the default is the last one that was mysql_connect() Open connection. If the connection is not found, the function will try to call mysql_connect() Establish a connection and use it. If an unexpected event occurs, no connection is found, or the connection cannot be established, the system will issue a warning message at the E_WARNING level.

Description

This function closes the non-persistent connection associated with the specified connection identifier to the MySQL server. If not specified link_identifierthen close the previous opened connection.

Return Value

Returns true if successful, false otherwise.

Tips and Comments

Tip:mysql_close() is usually not necessary because non-persistent connections that have been opened will automatically close after the script execution is completed.

Note:mysql_close() will not close a persistent connection established by mysql_pconnect().

Example

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
// Some code...
mysql_close($con);
?>