WordPress.org

Ready to get started?Download WordPress

Forums

Graceful "Error establishing a database connection" ?? (5 posts)

  1. yorokobi
    Member
    Posted 2 years ago #

    I am webmaster of a site on 1and1, and their system is configured so that the SQL databases are on a different computer then the WordPress site (note this is self hosted not using their TERRIBLY outdated "one click" install)

    Anyway, THAT means that if the SQL server gets overwhelmed by someone else, or goes offline, then the website displays

    "Error establishing a database connection"

    I'd REALLY like to make that into a graceful screen, "Please try again later, or try these links (links to other related URLs)" or something like that.

    So... Is there a plugin for this ? (I searched but found nothing) or does anyone know of a hook to use - as is good practice, I don't alter core WP files.

    TIA.

  2. ClaytonJames
    Member
    Posted 2 years ago #

    I'm not sure if there is a plugin for that particular issue... heaven knows there's one for almost everything else these days... but the error message in itself suits a very pointed purpose for webmasters and troubleshooters alike. It identifies without question, that the database connection is not available. An attempt to disguise it with a more pleasant message may just be masking the issue that the hosting service can't reliably provide a consistent level of performance for their accounts.

    I should think that repeated disappearances of your database connection would be sufficient motivation for an immediate move to a new host.

    That being said, look at line 3273 in /wp-includes/functions.php

    That seems to imply that the function is already supported. I've never tried it, but it looks like if you create a custom error page and name it db-error.php, then place it in the /wp-content directory, that might do it. Like I say, I've never done it, but it seems to be something that might be worth trying. If you try it, will you let me know if it works or not? Thanks!

    [edit] .. I just tested this on a 3.3 beta install. It worked like a charm for me.

  3. ClaytonJames
    Member
    Posted 2 years ago #

    Huge Bonus Points!!!

    WordPress 3.3 beta 2, just showed me the file I created and uploaded to /wp-content while testing this. On my plugins page in WP 3.3, I now see this category and description:

    Drop-ins (1)

    "Drop-ins are advanced plugins in the wp-content directory that replace WordPress functionality when present."

    1 item

    Plugin - db-error.php

    Description - Custom database error message.

    Absolutely Outstanding! :-)

    ... is this something I've just never noticed, or something new?

  4. fireproofsocks
    Member
    Posted 2 years ago #

    Sounds like you need a better host. It's not acceptable if the database goes in and out like that.

  5. yorokobi
    Member
    Posted 2 years ago #

    Thanks to all. I don't want to hide what happens, but I do want to offer alternative links and so on, like a "friendly 404 page" does.

    As to hosts, I agree, but this is a client and I have no control over the host. In about 5 years it's happened once, but that was enough for me to see that it was something that needed a better result then the plain output from a default install.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.