Page 1 of 1

closing db connections

Posted: Mon Dec 01, 2003 7:30 pm
by microthick
do u consciously close your db connection every time you're done with it?

what happens if i just continue on to another page without closing the connection... is this bad practice?

Posted: Mon Dec 01, 2003 9:49 pm
by m3mn0n
I always close it. Though I did use an open source script where it wasn't closed in a hundred or so places but it didn't make for any security leak or MySQL errors. Just bad practice. I recommend doing so, especially if you're going to release the application to the world.

Posted: Tue Dec 02, 2003 5:10 am
by Weirdan
If connection isn't persistent it will be closed during PHP shudown sequence.

Posted: Tue Dec 02, 2003 8:38 pm
by fractalvibes
Always good practice to close all connections, dispose of objects,etc.
after you are done with them. Esp. with anything where licensing gives you N number of concurrent instances and no more!
Some languages might have good garbage collection whilst others do not.
Run a tight ship in that respect and you'll be better off.

FV

Posted: Wed Dec 03, 2003 11:30 am
by JAM
Sami wrote:I always close it. Though I did use an open source script where it wasn't closed in a hundred or so places but it didn't make for any security leak or MySQL errors. Just bad practice. I recommend doing so, especially if you're going to release the application to the world.
I'd recommend to close it too.
Quoting php.net: "...all resources that were in use for this resource are made free by the garbage collector. For this reason, it is rarely ever necessary to free the memory manually by using some free_result function."

With my limited knowledge of english and how the Zend engine/garbage collector works, 'rarely' is not enough for me.