deltanovember deltanovember - 3 months ago 25
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



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