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 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 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 } 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. 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); } } ?> 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
Archived
This topic is now archived and is closed to further replies.