Database Error:

WordPress consist of PHP files which interact with the MySQL databases. It will generate the pages to the website. But if the database has crashed, it will lead to Database error shown as “Error Establishing A Database Connection“. This database error page will be seen as a default error page. The default page can reveal some sensitive information too. To prevent this, we can manage our custom Database Error page in WordPress.

Working principle:

Basically, it works automatically in WordPress. If a database error is thrown by the server, then the WordPress will search for the custom error page. If it is available then it will show the custom error page, otherwise, it will display a default database error page.

Custom error page setup:

To create the custom page error, first of all, you need to create a file called db-errors.php in the wp-content folder. Then add the following php code in that file.

// custom WordPress database error page
header(‘HTTP/1.1 503 Service Temporarily Unavailable’);
header(‘Status: 503 Service Temporarily Unavailable’);
header(‘Retry-After: 600’); // 1 hour = 3600 seconds
/ If you want to email yourself on an error
// mail(“”, “Database Error”, “problem with the database!”, “From: Db Error Watching”);
<title>Database Error</title>
body { padding: 20px; background: red; color: white; font-size: 60px; }
You got problems.

The above-mentioned code will help you in showing the custom error page. If you want to set up a notification when the server throws this error, then add your email in the mail line. We hope that this article will help you to add the Custom Database Error Page to your website. Like us on Facebook and Twitter.

Categorized in:

Tagged in: