Page 1 of 1
about closing database connection
Posted: Thu Aug 12, 2004 4:20 am
by bugthefixer
do we explicitly need to close connection
mysql_close($link)
or connection is automatically closed after execution of each page.
Posted: Thu Aug 12, 2004 4:32 am
by CoderGoblin
AS far as I am aware connections should get closed automatically in MySQL, I know this is the case with postgres. However it is good design practice to always ensure it is closed. It is not all that hard to do after all.
Normally you have three layers
<database load and save>
<process>
<output>.
Rather than wait for the output I tend to close the connection after either the database layer (if process does not touch the database which I try to avoid) or after the process layer but before the output.
It is the same with freeResult(). You shouldn't have to do it but it is good practice to.
Posted: Thu Aug 12, 2004 5:06 am
by anjanesh
According to php's manual :
Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.