Try this
if(mysql_connect(connection_parameters))
{
put your db select statement here
}else{
die ("Unfortunately there is an error with the system - .........");
}
Then if the server is down (i.e you cannot connect to the db server the messge is shown instead of all the horrible code in your first post
HTH
GM