Page 1 of 1
Close connections on every page?
Posted: Wed Mar 08, 2006 12:48 am
by Citizen
Should I mysql_close($dbh); on every page that I connect to my database on? Should I even close it on pages that use sessions? What is the effect?
Posted: Wed Mar 08, 2006 1:20 am
by feyd
This is a security question?
It's not absolutely needed for the most part. However, if you're running into connection limit issues, it's best to add them immediately after the last database dependant call is made to make sure connections are open as short as possible.
Posted: Wed Mar 08, 2006 1:52 am
by s.dot
Your database connections are automatically closed by PHP after execution of the script. So the only effect not closing them would have is that your connections would be open microseconds longer. Not really a security issue.
Posted: Wed Mar 08, 2006 2:07 am
by AGISB
feyd wrote:This is a security question?
It's not absolutely needed for the most part. However, if you're running into connection limit issues, it's best to add them immediately after the last database dependant call is made to make sure connections are open as short as possible.
This is a good advice but here is a little tip if you do it like this.
If you edit your code sometime in the future you most likely forget that you did that. So make a mental note that if a database query does not work it is that the connection is closed. It took me some time to figure that out and that error drove me nuts before I did
