Moon
Moon

Reputation: 20012

PHP:MySQL what if we don't close the opened connections

In PHP + MySQL

This is:

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

what we do to open a connection.

And this is:

mysql_close($conn);

what we do to close the connection.

Upvotes: 3

Views: 2053

Answers (3)

Alex Pliutau
Alex Pliutau

Reputation: 21957

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.

Upvotes: 2

Justin Ethier
Justin Ethier

Reputation: 134167

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.

Upvotes: 6

Chris
Chris

Reputation: 12078

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.

Upvotes: 1

Related Questions