WordPress Database Connection Error

The other day I ran into a problem with one of my clients websites that was throwing the Nemesis error for all WordPress developers:

Error establishing a database connection.

Not a very nice error to present to your users.

I was wondering if it was possible to change this message to something more meaningful, or at least, more user friendly. So I came up with the following message instead:

This website is currently experiencing some heavy traffic and is unable to fulfill your request.

The website administrators are working hard at the moment to allocate extra resources.

We appreciate your patience.

The idea is not to present the user with some technicality but to turn the error message into something slightly more positive. If a website is receiving “heavy traffic” then it must be in high demand right? This means that many people want what’s on this website. So even though the website is returning an error it’s not because it’s broken but because the demand is so high, which sort of makes it OK…

Of course, in reality there is a problem with the website that needs to be fixed but I think that presenting a message with a different tone can make a huge impact on how the visitor perceives the problem.

To change the error message for your WordPress installation create a file called db-error.php located in the wp-content directory of your WordPress installation. You can simply fill it with the HTML that you want. However, be aware that at this point the template system has not been loaded yet so you can’t access any of your template resources. At first glance this might come across as an oversight on the behalf of the WordPress core developers but many templates/themes need to access the database for various bits of information such as the website title etc. So you have to make do with the static page.

This entry was posted in Programming. Bookmark the permalink. Both comments and trackbacks are currently closed.