views:

37

answers:

3

in PHP + mySQL

$conn = mysql_connect("server","user","pass");
mysql_select_db("datbasename");

this is what we do to open a connection. and

mysql_close($conn);

this is what we do to open a connection.

  • WHAT if we don't close the connections...what are going to be the effects
  • after what CONDITION the opened connections a re automatically closed
A: 

In a small application nothing at all. PHP is nice and cleans up memory/closes connections upon scripts execution completion. If you are concerned about resources and utilization then I suggest closing your connections when you are finished using them.

Chris
+4  A: 

From the PHP documentation for mysql_close:

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.

Justin Ethier
A: 

With mysql_connect connection will close, when script is ended.

Mysql_pconnect doesn't close connection.

If you work with more then 1 mysql servers, is necessery to control your closing connections, or create some persistance.

Alexander.Plutov