Re: MySQL close connection, what's the purpose?
| From: | Jasper Bryant-Greene | Date: | Sun, 02 Apr 2006 01:48:08 +0000 |
| Subject: | Re: MySQL close connection, what's the purpose? | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233076@lists.php.net to get a copy of this message | ||
Robert Cummings wrote:
On Sat, 2006-04-01 at 20:15, tedd wrote:It would be interesting to actually run a script that opens, retrieves, and inserts data -- let's say 50k times. What's the time difference between one open, 50k retrieves/inserts, and one close-- as compared 50k opens retrieve/insert closes? [snip]
Yeah, e.g. I have a database objects layer that means I only write SQL in classes, everything else is just calling object methods. I create the database object at the start of every script but that doesn't necessarily open the database connection. The database connection is opened when I make my first query. That way if a page does no queries (I use APC caching so it is fairly common for a page to do no queries) then no database connection is opened. I never close connections; PHP does that for me and has never caused any problems doing that. I don't see it as sloppy programming, it is a documented feature that PHP closes resources such as database connections at the end of the script. But, as has been said, each to their own. -- Jasper Bryant-Greene General Manager Album Limited http://www.album.co.nz/ 0800 4 ALBUM jasper@album.co.nz 021 708 334Everyone has their own way.I'm not going to advocate either style since both have their merits depending on where and what you are doing. My input is to advocate a database wrapper layer such that the database connection semantics are remove from general development. In this way you might have the following: [snip]