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

cafeine cafeine at no-log.org
Mon May 2 01:24:32 EST 2005


Gareth Anderson <somecsstudent at gmail.com> writes:

> Which way is preferred?
>
> The PHP files are doing a little processing, mostly text based so they
> should run incredibly fast. 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?
>
> Regards,
> Gareth

Hi,

during my short career as a PHP/MySQL developer, I didn't quite bother
about closing and reopening database connectivity, I kept the same
connection opened and tried keeping all database-related stuff at one
point of the code (ie fetch all data in a few SQL calls, then feed it to
the PHP application). I found it helped me learn quite a few SQL tricks
(so I didn't have to preprocess my queries with PHP).

I also used mysql_pconnect() in situations where my application was the
only mySQL client. You might be interested in looking at it.

That said, I'm a self-taught developer so there are quite a few things I
may be missing knowledge of, so I'd be interested in reading what the
others on the list have to say...

HTH,
cafeine

> Note: the way I do this does not effect my marks for the subject. The
> lecturer is not very familiar with PHP/mySQL, thats why we're doing an
> "individual project".
> So in other words I'm looking for general comments on this.
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming

-- 
"Men get defensive when women critique their oppressive and sexist
behaviors. Rather than listening and benefiting from criticism, a
defensive stance is taken and women's voices are ignored once again."
-Angela Beallor



More information about the Programming mailing list