By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Efficiency of mysql_close()

P: n/a
Hello,

I am working on a script for PHP that handles mysql_connections.
Right now, each time I query the database, i open the connection using
mysql_connect(), and after I get my resource result, I use
mysql_close(). I have heard from many people that it is common
practice to open a connection at the beginning of the script, and
since the connection closes at the end of the script, it is then
closed.

My question is this: Which is the better way? To open the script
at the top, and then let the connection close at the bottom? As this
may be a controversial issue, and if no answer is found, what are the
advantages?

Does anyone know if the resources used, and the time elapsed to make
a db connection is significant enough to warrant leaving the
connection open the entire time?

What are the advantages?

Thank you.

Jun 4 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 4, 12:23 pm, huckphin <chad.rhy...@gmail.comwrote:
Hello,

I am working on a script for PHP that handles mysql_connections.
Right now, each time I query the database, i open the connection using
mysql_connect(), and after I get my resource result, I use
mysql_close(). I have heard from many people that it is common
practice to open a connection at the beginning of the script, and
since the connection closes at the end of the script, it is then
closed.

My question is this: Which is the better way? To open the script
at the top, and then let the connection close at the bottom? As this
may be a controversial issue, and if no answer is found, what are the
advantages?

Does anyone know if the resources used, and the time elapsed to make
a db connection is significant enough to warrant leaving the
connection open the entire time?

What are the advantages?

Thank you.
Open the connection once at the top, then forget about it. Opening it
for each and every query is wasteful (the overhead to connect is
generally high). You don't need to close it explicitly, either -- it
will be closed automatically when the script is done.

Jun 4 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.