United States (change)
Shortcuts: Downloads Fedora Red Hat Network
Account Links: Cart Your Account Logout
Closing a connection to a MySQL database using PHP is just as simple as opening a connection. There is only one call needed to a built-in PHP function. The only catch is that you need to pass the link identifier as the only argument to the function.
To close your MySQL connection, use the mysql_close() built-in PHP function. Example usage would look like the following:
<?php mysql_close($db_link); ?>
In this usage, the variable $db_link was established when you open the connection. See other articles in the Knowledgebase that can help you establish and open a connection to MySQL using PHP for a web page with the mysql_connect() built-in PHP function. Detailed information on the mysql_close() PHP function can be found at php.net specifically at the following location: http://www.php.net/manual/en/function.mysql-close.php
Tip: Put this at the end of your PHP script when you are done making calls to the MySQL database.
Frequent opening and closing connections to a MySQL database can be CPU intensive, on heavily loaded servers it might be worthwhile investigating persistant connections. More information for using persistant connections is available on the php manual page for mysql_pconnect.