Support » Fixing WordPress » Redirect on db errors.

  • Hi,
    My host has had some trouble recently with their MySQL server and occassionally readers have been unable to view my site because WP can’t make a db connection.

    I don’t like the standard WP error page and want it to look like the rest of my site. Is there a way to redirect WP to another page if this happens?

    I have created an errorindex.php within my current theme folder and edited the following in wp-db.php:
    function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    if (!$this->dbh) {
    <?php include('errorindex.php'); ?>

    I removed the standard text and added the include errorindex call. I have a number of questions.
    1. Will the code work. I don’t know of a way to test it. Accessing the page directly, everything is fine but that doesn’t mean it will work!
    2. The Errorindex also makes calls to other pages (nothing from within the db!) will this make a difference?


Viewing 3 replies - 1 through 3 (of 3 total)
  • It won’t work the way you have it coded. Replace the if with this:

    if (!$this->dbh) {

    Thank you,
    Twice in one week you have come to my rescue within a few minutes of my posting.

    Is there a way for me to test it, without asking my hosts to break the MySQL server?!

    I do something quite similar, so I’ll guarantee it.* :)

    I would recommend verifying the full path on your server to where errorindex.php resides, and use that in your include instead of just the filename.

    * But if you must, give your db an incorrect name in wp-config.php.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect on db errors.’ is closed to new replies.