deltanovember deltanovember - 1 year ago 68
PHP Question

How do I check if PHP is connected to a database already?

Basically in pseudo code I'm looking for something like

if (connected_to_any_database()) {
// do nothing
else {

How do I implement


Answer Source

Have you tried mysql_ping?:


Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted.

or second approach (but mysql_ping is more reliable in this case):

$link = mysql_connect('localhost','username','password');
if($link == false){
    //try to reconnect
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download