FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to preset the MySQL error?





Diablosblizz
Hey, I was wondering if it is possible to set a custom error if the database could not be connected to? I'm starting to "attempt" to create a CMS, and I want it to show a offline message when the database is either down to the information inputed has changed somehow.

Thanks, and Kind Regards!
woodenbrick
To do this you suppress the normal error message by using '@' in front of the function
eg.
Code:

@$connection = mysql_connect($hostname, $username, $password);
if(!$connection){
echo "Sorry, we cannot connect you to the database at this time.";
}
Diablosblizz
Yes, that does work but it still shows the other MySQL errors. I want them to be gone and to just show the error I specify. I also want my site to not be available, but I suppose I must do that on each an every page...

Is there anyway to only display my error nothing else. Not even my template?

Thanks and kind regards.
rvec
instead of
Code:
if(!$connection){
echo "Sorry, we cannot connect you to the database at this time.";
}

use
Code:
if(!$connection){
die(Sorry, we cannot connect you to the database at this time.);
}

and make sure this is done before any other output.
Diablosblizz
Figured out that I can set a variable in the or die part.

Code:
$connection = mysql_connect("$host", "$user", "$password") or die($error);
Related topics
Mysql error!
MySQL error 1604
[solved] Weird mysql error
Suppressing mysql error
[mySQL] Error I cannot Debug
MySql error: Column count doesn't match value count at row 1
Mysql Error
MySQL error
Error connecting to mysql ; please help
Mysql error: Warning: mysql_num_rows():
mysql error
MySQL error
Urgent! MySQL error!
MYSQL Ajax im Installation Error
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.