Basically in pseudo code I\'m looking for something like
if (connected_to_any_database()) {
// do nothing
}
else {
mysql_connect(...)
}
Have you tried mysql_ping()?
Update: From PHP 5.5 onwards, use mysqli_ping() instead.
Pings a server connection, or tries to reconnect if the connection has gone down.
if ($mysqli->ping()) { printf ("Our connection is ok!\n"); } else { printf ("Error: %s\n", $mysqli->error); }
Alternatively, a second (less reliable) approach would be:
$link = mysql_connect('localhost','username','password');
//(...)
if($link == false){
//try to reconnect
}