WordPress.org

Ready to get started?Download WordPress

Forums

Redirect on db errors. (4 posts)

  1. planetphillip
    Member
    Posted 9 years ago #

    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) {
    $this->bail("
    <?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?

    TIA
    Phillip

  2. Kafkaesqui

    Posted 9 years ago #

    It won't work the way you have it coded. Replace the if with this:

    if (!$this->dbh) {
    include('errorindex.php');
    die;
    }

  3. planetphillip
    Member
    Posted 9 years ago #

    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?!

  4. Kafkaesqui

    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic