Efficiency of mysql_close()



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.

.



Relevant Pages

  • Re: I am a php noob and have a quick question
    ... $link, when a connection is established, is a resource id. ... for you to refer to this particular database connection. ... If you look up the mysql functions you will discover that some of them have ...
    (comp.lang.php)
  • Re: Apache mod_rewrite/RewriteMap prg: and perl script
    ... > input for some hours and then go on (especially if the database is on ... > a remote box - tcp connection might have gone dead for whatever ... What *does* happen is that the script gets garbled. ... different garble each time you hit it. ...
    (comp.unix.admin)
  • Need help with ASP script.
    ... the beginning process of having a webpage that will direct students to ... I had downloaded a free ASP script which basically uses a ... 'Check the database to see if user exsits and read in there password ... 'Database connection info and driver ...
    (microsoft.public.inetserver.asp.general)
  • Re: Difference between storing files on folder and in mysql db
    ... a separate instance of an image display script (and a separate ... connection if images were stored in the file system. ... know or care if the image is from a database or not. ... but the DB server does. ...
    (comp.lang.php)
  • Please Help...
    ... I cannot connect to my database using JNDI., ... but the tomcat 5.5.7 installation is not playing. ... Resource reference to a factory for java.sql.Connection ... connection which says to me server.xml entries are correct. ...
    (comp.lang.java.databases)