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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.