Forum Moderators: coopster
<?php
$link = mysql_connect("SERVER", "USER", "PWD") or die("Could not connect : " . mysql_error());
?>
True to form, after a 60 second timeout I get the error displayed on the screen. Well, rather than display that error I'd like to redirect to a pure html document. So, I thought that the solution might be something like the following example, where I attempt to redirect the page to an html document.
<?php
$link = mysql_connect("SERVER", "USER", "PWD");
if (!link) {
header ("Location: http://example.com/index.html");
}
?>
Of course, by time I figured this out and got it uploaded, the server connection was restored. However, it seems like this will work. Notice that the redirect does not go to www, but to the root. There is a series of plain html documents there (not indexed) that will at least allow the visitor to see something. There are also .htaccess issues to work out, assuming everything else works the way I think it will. Any thoughts?
Also, I've been looking around for more documentation on mysql_connect and how to capture other errors, such as invalid user or password. It seems like it would be possible, but I haven't found anything yet.
Don't forget the $ at: if(!$link) {
If you want to find out what error is occurring with a failed mysql_connect you could do this:
$link = mysql_connect("SERVER", "USER", "PWD") or die("Error :".mysql_error());
I'm not sure what it does when there's a timeout though.. maybe nothing.
use the error number as well as the mysql_error for the message
[php.net...]
you can use their messages or just get the error number and use your own user friendly message.
you'll need this too
[dev.mysql.com...]
This should also prevent SE indexing of pages displaying an error notice or warning.