Re: MySQL close connection, what's the purpose?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
On Sat, 2006-04-01 at 20:48, Jasper Bryant-Greene wrote:
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.

There's smart lazy programming, and sloppy lazy programming. I don't
trust anything magical in PHP. Most of us are familiar with the magic
quotes and global vars fiascos *LOL*. But hey, if you can squeeze a
rewrite of an application out of a client for relying on dirty
techniques, who am I to critique your forward thinking manipulative
methods -- not to say that's your intent -- but I'd sure question your
motives and judgement if it comes around ;)

I very much doubt PHP will ever enforce the closing of resources such as database connections at the end of every script. That would be a needless BC break.

Also, I do it this way because some projects that use my framework want persistent connections. If my framework closed connections automatically then that wouldn't be possible.

Of course, it wouldn't exactly be a rewrite to make it close the connection at the end of every script before PHP did, if I'm proven wrong and it one day is necessary. I'd only need to change the database objects layer.

--
Jasper Bryant-Greene
General Manager
Album Limited

http://www.album.co.nz/     0800 4 ALBUM
jasper@xxxxxxxxxxx          021 708 334

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux