Re: error for mysql
| From: | David Robley | Date: | Wed, 11 Oct 2000 04:16:44 +0000 |
| Subject: | Re: error for mysql | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19487@lists.php.net to get a copy of this message | ||
On Wed, 11 Oct 2000, Kurth Bemis wrote:
> At 12:54 PM 10/11/2000 +1030, David Robley wrote:
>
> ok then....thats doable...how would i make the error then?
>
Very simply:
mysql_connect(host, user,pass) or die ("Error occured");
or you could build a series of events that result from a failed connection.
I use this script as an include file at the beginning of any scripts that
require a mysqld connection:
<?php
/* This script attempts to connect to the MySQL daemon on the local host.
Following an unsuccessful attempt to open a connection, an email is sent to the
site maintainer on the local host as the webserver user and a message is also
returned to the client to advise that there is a problem.
This is probably best run near or at the beginning of a script. That way, if the
connect fails, just pass out the error message and exit. */
if(!mysql_connect("localhost", "nobody")):
/* Return a message to the client and send mail to the administrator */
$maintainer = "webmaster@www.nisu.flinders.edu.au"; /* Who gets the mail */
$subject = "MySQL Database Failure";
$page = ereg_replace("~","",$PHP_SELF); /* Page on which the problem
occurred */
$when = date("H:i D d M Y");
$who = $REMOTE_HOST;
$server = $SERVER_NAME;
$where = $REMOTE_ADDR;
$errno = mysql_errno();
$message = "An unsuccessful attempt was made to access the MySQL daemon on the $server
server.\n $message .= "This probably means that the daemon has died.\n\n";
$message .= "Details of the event are:\n\n";
$message .= "Date: " . $when . "\n";
$message .= "Page: " . $page . "\n";
$message .= "From: " . $who . " " . $where . "\n";
if(!empty($errno)):
$message .= "Error no: " . $errno() . ": " . mysql_error() . "\n";
endif;
$message .= "\nSo get off your bum and fix it!";
/* Send the mail message */
mail("$maintainer","$subject","$message","From: Big
Brother");
/* Output the error message to the client */
echo "<BODY BGCOLOR=\"#FFFFFF\">";
echo "<H1 ALIGN=center>There is a Problem!</H1>";
echo "<TABLE BORDER=\"2\" WIDTH=\"75%\" ALIGN=center
CELLPADDING=\"3\" BGCOLOR=\"#EE0000\">";
echo "<TR><TD><IMG SRC=\"/gifs/face.worried.gif\" HEIGHT=136
WIDTH=210>";
echo "<TD><FONT COLOR=\"#FFFFFF\"
FACE=\"Helvetica,Arial\">";
echo "The database software that services your request is currently not operational. ";
echo "A message has been sent to the Webmaster to alert him to the problem.<P>";
echo "The time in Australia is currently ";
echo date("h i a on l d F Y<P>");
$now = intval(date("H"));
if(($now < 9) || ($now >= 17)): /* Pretend I'm not here before 9 or after 5 */
echo "At this time, it is likely that the Webmaster is off doing those thing that Webmas
echo "(and other mortals) do in their leisure time.<BR>";
echo "Please try again later when the Webmaster has had a chance to
fix the problem.";
else:
echo "As this is within working hours, you may wish to wait a short while and try again.
echo "Hopefully, in the meantime the Webmaster will have had time to rectify the problem
endif;
echo "</FONT></TABLE><P><HR>";
echo "</BODY></HTML>";
exit;
endif;
?>
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA