mysql_connecet returns false if the connection fails.
$username="XXXXXXXXX";
$password="XXXXXXXXX";
$database="XXXXXXXXX";
$hostname="XXXXXXXXX";
$hostname2="XXXXXXXXX"; // let's assume they have the same username and pw
$conn=mysql_connect($hostname,$username,$password); //Connect to the database.
if (!$conn) {
mysql_close($conn);
echo "Cannot connect to DB1";
$conn=mysql_connect($hostname2,$username,$password); //Connect to the database.
if (!$conn) {
mysql_close($conn);
echo "Cannot connect to DB2";
die('No DBs');
}
}
else {
// $conn has your connection
}
similar behavior with mysql_select_db (it returns false if it fails)