You are here:  » Closing Database Connections

Support Forum



Closing Database Connections

Submitted by crounauer on Tue, 2007-09-04 11:10 in

Hi David,

I am bust reading up on closing database connections

mysql_close($link);

and was wondering why in the PT script it isn't used? Everything I have read suggests that it is good practice to utelise it as much as possible.

I can't figure out what your reasoning might be?

Thanks,
Simon

Submitted by support on Tue, 2007-09-04 11:14

Hi Simon,

It's for performance reasons.

PHP automatically closes all handles (files, database connections) at the end of the script anyway; so there isn't really any need to keep closing them manually, and if you don't - the MySQL library re-uses an existing connection. Therefore, for every Price Tapestry page view there is only ever one MySQL connection made, which is kept open and therefore reused for every query on the page.

Cheers,
David.