[prog] MySQL connections from PHP files - Close or keep it open for queries?

Allie Micka allie at pajunas.com
Mon May 2 02:44:45 EST 2005


Hi Gareth,

cafeine has it right - there's substantial overhead associated with all 
those mysql connections, so repeatedly dialing in and hanging up is 
more expensive.

Depending on how your application behaves, cafeine's other piece of 
advice is useful:  Try to keep all of your SQL queries and logic 
together in your file, close the connection, and then do your 
post-processing/display work.  This approach is usually more logical 
and readable, and it trains you to separate data,logic and display in 
your application.

Obviously, there will be cases when you need to process query results 
and then run additional queries based on the result, and there are 
cases when your data set is so large that it is impractical to cram it 
all into memory for the next step of the process.

On May 1, 2005, at 7:39 AM, Gareth Anderson wrote:
>  However is it perferred to keep an open
> connection to the database with multiple queries?
> Or to have an individual connection/disconnection with each query?


Allie Micka
pajunas interactive, inc.
http://www.pajunas.com/

scalable web hosting and open source solutions



More information about the Programming mailing list