I have php script which should try to connect to DB in local site. If the local DB is not available it should try to connect to DB on remote server.
$dblink = mysql_connect(DBHOST_LOCAL, DBUSER, DBPASS) or $RC = 1;
if($RC) {
$dblink = mysql_connect(DBHOST_REMOTE, DBUSER, DBPASS) or die('Could not connect'.mysql_error());
}
The problem is that I don't want to display Warning message on page if connection failed the first time. Is there any way to disable the warning message only for mysql_connect() function?
Yes, add an @ sign like so to suppress warning / error messages, then do the error once your own:
$dblink = @mysql_connect(DBHOST_LOCAL, DBUSER, DBPASS);
if (!$dblink)
{
$dblink = @mysql_connect(DBHOST_REMOTE, DBUSER, DBPASS);
}
if (!$dblink)
{
$message = sprintf(
"Could not connect to local or remote database: %s",
mysql_error()
);
trigger_error($message);
return;
}
Take care that you need to handle all error reporting your own then. Such code is hard to debug in case you make a mistake.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With