Jump to content

PHP To check if mysql connection is open?


Shaun

Recommended Posts

Hi, im a little stuck trying to work out how to do this.

 

I want to check it there is a mysql connection open on my page and if so, mysql_close($conn);... The reason is that my pages are on a dynamic template, and I would like to chuck this right at the end of the page.

 

is it possible?

 

Thank you, Shaun

All resources used on a page are released/destroyed when execution of that page ends. It is not necessary to close a mysql connection at the end of a page, unless you want to close it earlier in the page to free up a connection sooner.

Thanks, I didnt know that it closed them at the end.

 

However, I feel I still need to add this as on some of my pages there just simple isnt a mysql connection active, and because I have the mysql close command from above in my bottom template, I recieve errors on those pages.

 

 

thanks, Shaun

  • 3 years later...

I know I'm digging up an old thread, but why don't you just use the @ error suppressor?

I see no drawback to it, you can try to close a connection and regardless of whether or not it exists you'll get the same quiet result.

 

@mysql_close($conn);

 

...where '@' says "don't tell me if there's an error".  Since it'll only throw when you try to close a connection that's not close-able, then you're not creating room for any sort of problems.

 

Hope this helps somebody who stumbles across this on google or whatever. :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.