You are here: Re: PHP error if MySQL server is down « All PHP « IT news, forums, messages
Re: PHP error if MySQL server is down

Posted by MaKroZ on 12/16/05 00:59

On Thu, 15 Dec 2005 10:50:16 +0100, Jim wrote:

> Some of the pages on my website was down for 1.5 hours the other day because
> the shared MySQL didn't work. Rather than having PHP returning an error, I
> would like the page to show anyway without any error messages but with an
> error e-mail sent to me. This is the code I'm using to connect to the
> database:
>
> $link = mysql_connect($db_host,$db_user,$db_password);
> if (!$link) { die('Could not connect: ' . mysql_error());}
> mysql_select_db($db_name) or die(mysql_error());
> $sql = "<cut>";
> $query = mysql_query($sql);
> $array = mysql_fetch_array($query);
> mysql_close($link);
>
> What do I do?

I'd suggest to rewrite your code in something like this:

$link = mysql_connect($db_host,$db_user,$db_password);
if (!$link) {
$message = mysql_error();
mail( <-- something to send an email with $message to you --> );
echo "a page without any error messages... blah blah blah..";
die();
}
else {
mysql_select_db($db_name) or die(mysql_error()); $sql = "<cut>"; $query =
mysql_query($sql);
$array = mysql_fetch_array($query);
mysql_close($link);
}

--
nn = MaKroZ =
(oo) My bookmarks:
| | http://www.theisplist.com
|/\| http://www.10pieces.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация