Re: Efficiency of mysql_close()



On Jun 4, 12:23 pm, huckphin <chad.rhy...@xxxxxxxxx> wrote:
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.

.



Relevant Pages

  • ADO Object in VB Script Only Calls SQLGetData for column 1
    ... I try I can only get the script to retrieve the first column of my query. ... Dim adoConnection As ADODB.Connection ... '—Build our connection string to use when we open the connection -- ...
    (microsoft.public.data.ado)
  • Re: dialup solution (as seconary connection / iptables )
    ... ip-down is launched by pppd only after the PPP link no longer available ... first with MINICOM or is PAP and script not mutualy exclusive? ... do have to "make the connection first with MINICOM." ... If you use the Linux box and route the news IP address to it on each ...
    (comp.os.linux.networking)
  • Re: mysqli connections and oop
    ... need to do all processing in a script before I display a page that will ... But it will most probably NOT terminated the execution of the script. ... this means that NO lasting connection is build ... Why does it not carry the mysqli connection? ...
    (comp.lang.php)
  • Re: mysqli connections and oop
    ... And here is the script that execute this ... lose a mysqli connection upon the reload of the page? ...
    (comp.lang.php)
  • Re: Does apache stop a script mid execution ?
    ... If the user calls a time consuming script and then stops or refreshes ... How does it relate to e.g. a script performing a large mysql query? ... 2.b) how the connection is set up. ... the server stops the script execution. ...
    (comp.lang.php)