Account Links: Cart | Your Account | Logout

Skip to content

Red Hat Knowledgebase

Red Hat Knowledgebase Search:

Updated Within the Last:

New Solutions within the last day New Solutions within the last week New Solutions within the last month

Browse by topics:


Click to View a Topic
Red Hat Enterprise Linux > Web Server > Issue <<  31 of 73 >>

Solution Tools:


Email a Solution Postcard Printer version Submit a comment on this answer Update notifications Request an answer Back

Article Reference

Article ID: 4604
Last update: 05-11-06
Issue:
How do I close a connection to MySQL using PHP?
Resolution:

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.


How well did this entry answer your question?


good wrong incomplete out of date
Red Hat Enterprise Linux > Web Server > Issue <<   31  of  73  >>