Shaun Posted October 12, 2008 Share Posted October 12, 2008 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 https://forums.phpfreaks.com/topic/128105-php-to-check-if-mysql-connection-is-open/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 12, 2008 Share Posted October 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/128105-php-to-check-if-mysql-connection-is-open/#findComment-663425 Share on other sites More sharing options...
Shaun Posted October 12, 2008 Author Share Posted October 12, 2008 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 https://forums.phpfreaks.com/topic/128105-php-to-check-if-mysql-connection-is-open/#findComment-663431 Share on other sites More sharing options...
Shaun Posted October 12, 2008 Author Share Posted October 12, 2008 actually. come to think of it.. why dont I just close them on each page? lol Link to comment https://forums.phpfreaks.com/topic/128105-php-to-check-if-mysql-connection-is-open/#findComment-663484 Share on other sites More sharing options...
dudewad Posted November 2, 2011 Share Posted November 2, 2011 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. Link to comment https://forums.phpfreaks.com/topic/128105-php-to-check-if-mysql-connection-is-open/#findComment-1284346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.