How To Close MySQL Connection Objects


How To Close MySQL Connection Objects? - MySQL FAQs - PHP Connections and Query Execution



MySQL connection objects created with mysql_connect() calls should be closed as soon as you have finished all of your database access needs by calling mysql_close($con) function. This will reduce the consumption of connection resources on your MySQL server.

If you forget to call mysql_close(), PHP engine will automatically close your connection objects, when your PHP script reaches the end. The following PHP script shows a good example of mysql_close():

  $con = mysql_connect('localhost:8888', 'dev', 'iyf');
  if (!$con) {
    print("There is a problem with MySQL connection.\n");
  } else {
    print("The MySQL connection object is ready.\n");

2007-05-10, 4841👍, 0💬