MySQL
mysql_close function
mysql_close is a function used by PHP to close the connection with the MySQL database.
Basic usage of PHP mysql_close
bool mysql_close ( resource $link_identifier = NULL )
Fill in the MySQL connection variables to be closed in the parentheses. If it is closed successfully, it will return true, and if it fails, it will return false.
PHP mysql_close example
<?php
$MySQLLink=mysql_connect('localhost', 'mysql user account', 'mysql user password');
if(!$MySQLLink){
die('連線失敗: ' . mysql_error());
}
mysql_close($MySQLLink);
?>
This is a fairly basic example of a connection between PHP and MySQL . The mysql_connect used in the first line is a function to open the MySQL connection, and the if condition in the second line is judged. If the connection fails, an error message will be displayed through the mysql_error function. If the connection is successful, use mysql_close to close the $MySQLLink connection.$MySQLLink=mysql_connect('localhost', 'mysql user account', 'mysql user password');
if(!$MySQLLink){
die('連線失敗: ' . mysql_error());
}
mysql_close($MySQLLink);
?>
Postscript, is there a need for the existence of this function?
Although mysql_close seems necessary to exist, in fact, the purpose of the mysql_close function is also very strange. Since the connection between PHP and the MySQL database is opened, it will be automatically closed after the entire PHP script is run. In other words, In fact, the mysql_close function is not needed . I have seen messages on the official PHP website stating that the mysql_close function is deprecated in PHP 5.5.0, and this function will be deleted in future versions, but in MySQLi or PDO_MySQL The extension can still be used, please refer to this description on the official website: PHP: mysql_close-Manual .
Post a Comment
0 Comments