Sure, and what you describe is often recommended. In general, you want two options for all your db connections. First, a successful connection, or second, some type of error handling.
So to achieve this most easily, we have the operator 'or'. What this will allow you to do is try one function, such as a mysql connection, and if it fails, PHP will then execute the associated or function, usually die or your own function.
$handler = mysql_connect($HostName, $UserName,$Password) or die(mysql_error());
That example is the most basic way of achieving some type of error handling, but as you see it unceremoniously kills the script if the connection fails and prints out a big fat error anyway.
Taking that a step further, we can create our own error handling function and use it in place of die(). It could be something simple, or it could package the errors and ship them off in an email to the administrator.
function err_rptr($error)
{
// some code that takes the error message and mails it whomever needs to see it, and
// returns some value to let the rest of the script know there was a problem
}
$handler = mysql_connect($HostName, $UserName,$Password) or err_rptr(mysql_error);
Sorry, but I am feeling too lazy to actually write a reporting function, but that is not terribly hard anyway. But what you see here is that instead of stopping when it encounters the error, the script will happily move right along.
You will need to adjust the script though to account for the fact that $handler may not be a valid connection handler if the connection silently failed, but again, that is all part of robust error checking.
Hopefully this provides some direction.