i suppose this could work.
if (!@mysql_connect()) {
$reason = mysql_error();
echo $reason;
}
i tested it on one win machine w/ no sql server installed, and the $reason was "Can't connect to MySQL server on 'localhost' (10061)"
as opposed to trying on a server with sql installed you will probably get something along the lines of "Access denied for user: 'somedefault@localhost' (Using password: NO)
that was the output on linux. the first error, 10061 usually is a socket error meaning it couldnt connect, so given mysql is running on the default port 3306 and you get the cant connect error, than it means either no server is running or its not on the default port, whereas the other error, access denied would mean it is running and gave a response to the connection. seems foolproof to me on any os.
you could even expand that to use
if (!function_exists("mysql_connect")) {
echo " sorry php isnt configured to connect to an sql server.";
} else {
//run code above
}
you can use strstr or regex on the $reason error to try to determine which error occured.