I manage a site that got a sudden and unexpected increase in traffic. Because of that, there are database access timeouts, with the "Error Establishing Database Connection" message.

This is not a configuration problem, but a 'load' problem. I have installed a caching plugin to help, which has helped somewhat.

What I would like to do, while still trying to mitigate traffic levels, is to change the message that is shown on the screen. Is there a filter or a template that can be used to change that error message.

Note that my question is not related to database authentication problems, but how to put up a message other than the one shown, or to redirect to a more 'static' page (that the caching plugin can help with). The hosting location cannot provide additional resources, and I don't want/need to change to a more powerful and expensive hosting solution.

up vote 2 down vote accepted

Basically, if you create a PHP file named db-error.php and put under /wp-content/, you'll get what db-error.php will have. Here is my template on CodePen.

This is example :

<?php

    header('HTTP/1.1 503 Service Temporarily Unavailable');
    header('Status: 503 Service Temporarily Unavailable');
    header('Retry-After: 3600'); // 1 hour = 3600 seconds
    mail("example@example.com", "Database Error", "There is a problem with teh database!", "From: Example.COM");

?>
<!DOCTYPE HTML>
<html dir="ltr" lang="en-US">
    <head>
        <title>503 Service Temporarily Unavailable</title>
        <style type="text/css">
            h1, p {
                font-family: Helvetica, sans-serif;
                font-size: 24px;
                color: #333;
                }
            p {
                font-size: 14px;
                }
        </style>
    </head>
    <body>
        <h1>Uff, you came and our server started to sink!</h1>
        <p>You did nothing wrong. We are sad but our server's condition is just bad out of load. Please check back after sometime.</p>
    </body>
</html>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.