M.O.S. Studios Posted June 20, 2009 Share Posted June 20, 2009 Hey, I'm making a function that detects if a user is logged in or not, in one part of this function I need to connect to the "mysql" db. I wanted to know if there is a code or builtin function of php that auto detects if a connection to the "mysql" db is already made or not??? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/163057-solved-detecting-a-mysql-connection/ Share on other sites More sharing options...
M.O.S. Studios Posted June 20, 2009 Author Share Posted June 20, 2009 btw i tried using the mysql_thread_id() and mysql_ping(), they work fine, how ever when no connection is found it creats a E_WARNING, that is a problem Quote Link to comment https://forums.phpfreaks.com/topic/163057-solved-detecting-a-mysql-connection/#findComment-860384 Share on other sites More sharing options...
RussellReal Posted June 20, 2009 Share Posted June 20, 2009 function error_function() { // this will trigger if mysql_connect fails.. } mysql_connect(...) or error_function(); you could also do.. if (mysql_connect(...)) { } else { // failure } Quote Link to comment https://forums.phpfreaks.com/topic/163057-solved-detecting-a-mysql-connection/#findComment-860393 Share on other sites More sharing options...
M.O.S. Studios Posted June 21, 2009 Author Share Posted June 21, 2009 thanks but that's not what I'm looking for, i don't need to know if the connection was succsessful, i need to know if there is already a connection made. basically i want to avoid connecting twice. Quote Link to comment https://forums.phpfreaks.com/topic/163057-solved-detecting-a-mysql-connection/#findComment-860429 Share on other sites More sharing options...
M.O.S. Studios Posted June 21, 2009 Author Share Posted June 21, 2009 figured it out, this is what i did <?php function logedin() { if(@mysql_ping()===FALSE) { include("admin/common/link.php"); $linked=TRUE; } // ... the log in verifier // if($linked==TRUE) { mysql_close($link); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/163057-solved-detecting-a-mysql-connection/#findComment-860432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.