mysql_close() Function in PHP

What is mysql_close function in PHP?
How does mysql_close() works?

Explanation

The mysql_close function is used to close MySQL connection.
Syntax
bool mysql_close ( [resource link_identifier])

Returns: TRUE on success, FALSE on error.
Once you have opened a connection to your MySQL database from your PHP document, you can close it again using the mysql_close() function with link identifier as argument. If link_identifier is not specified,then the last opened link is used.
Using mysql_close() is not usually necessary, as non-persistent open links are automatically closed at the end of the script's execution
mysql_close() will not close persistent links created by mysql_pconnect().
Example

<?php
// Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
print 'You are connected';
//close connection
mysql_close($link) ;
?>

See also: mysql_connect() and mysql_pconnect()

PHP Topics


Ask Questions

Ask Question