NYCPHP Meetup

NYPHP.org

[nycphp-talk] When to close a mysql connection

Jakob Buchgraber jakob.buchgraber at googlemail.com
Thu Jun 28 16:33:02 EDT 2007


David Krings wrote:
> Hi!
> 
> Up until now I always opened a db connection to MySQL, did my query 
> stuff and then closed the connection again, went on to the next script, 
> opened the db connection, did some more queries, closed the connection, 
> went to next script.....
> 
> Is there anything speaking against making the db link pointer to be 
> global, call the connection script once right at the start of the set of 
> scripts and then assume that it is just there?
> 
> Or asking differently, is there anything speaking against opening and 
> closing the db connection each time a set of queries is to be executed?
> 
> I just wonder if I make poor PHP / MySQL work harder than necessary.
> 
> David
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 

As long as you need to send queries to the database you should keep the 
connection open, because connecting to the database is very often the 
slowest part of the whole script.

- Jay

-- 
Sun Certified Programmer for the Java 2 Platform, Standard Edition 5.0



More information about the talk mailing list