note 72395 deleted from function.mysql-close by danbrown
| From: | danbrown@php.net | Date: | Wed, 17 Jun 2009 13:52:54 +0000 |
| Subject: | note 72395 deleted from function.mysql-close by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156979@lists.php.net to get a copy of this message | ||
Note Submitter: jonbarnett at gmail dot com
----
RonS is mostly incorrect about mysql_close. It's not necessarily good programming practice to
always explicitly close your database connect as it might be in other languages. Your connection
will be closed as soon as your script is finished, so there is almost never a need to call
mysql_close at the end of a script.
If you have a script that does a lot of queries, it's dangerous to overuse the mysql_close
function, as constantly opening and closing a connection can cause a lot of overhead, especially if
you're connecting to a remote database. If you are already connected to a database and try to
use mysql_connect again on the same database, then the same connection will be returned, and no new
connection will be opened. So, it's safe to overuse mysql_connect without overusing
mysql_close.
If you need to open multiple connections to the same database, then create two connections with
mysql_connect with the extra boolean argument to force a new connection to be made without reusing
the old connection.
The only compelling reason for using mysql_close is if your script is assuredly finished with the
connection, but still has a lot of processing left to do. It is almost never beneficial to open and
close the same connection throughout a script.