October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
PHP

How to Add a Custom Database Error Page in WordPress

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create db-error.php in your active WordPress content directory—usually wp-content/db-error.php—to replace WordPress’s default database-error display. Return HTTP status 500, and keep the page independent of WordPress and the database. This changes what visitors see; it does not fix the connection failure.

Where to put the custom database error page

WordPress looks for WP_CONTENT_DIR . '/db-error.php' when it handles a database error. In a conventional installation, that means wp-content/db-error.php. If the file exists, WordPress loads it for the error display; if it does not, WordPress uses its default display. See the official dead_db() reference.

If your site has a customized content directory, use that active directory rather than assuming it is named wp-content. Create the file using your hosting file manager, SFTP, or deployment process. Do not edit WordPress core files such as wp-includes/functions.php; the content-directory template is the documented customization point.

Create a standalone page and preserve HTTP 500

The template may be loaded while the database is unavailable, so keep it simple: use plain PHP and HTML, and do not rely on WordPress functions, theme templates, plugins, database queries, or assets whose delivery depends on the site working. The following minimal example returns the required error status before sending the page body:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
http_response_code( 500 );
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Temporarily unavailable</title>
</head>
<body>
  <main>
    <h1>We’ll be back shortly</h1>
    <p>This site is temporarily unable to connect to its database. Please try again later.</p>
  </main>
</body>
</html>

WordPress’s database-error reference says its default response sets status 500 to discourage search engines from caching the message and advises that custom database messages do the same. Do not replace that status with 200 just because the HTML page rendered successfully.

Use a calm, accurate message, and give visitors a support or contact link only if it works independently of WordPress and its database. Review the file through your normal site deployment process. The template’s purpose is to communicate an outage, not to conceal it from monitoring systems or repair it.

Check that you are editing the right file

db-error.php and db.php are different WordPress mechanisms, despite their similar names.

File What it does For a custom error page?
wp-content/db-error.php Provides the display WordPress loads in its database-error path. Yes.
wp-content/db.php A database drop-in that can replace or extend the global $wpdb object. No. It is for database-layer customization, not the visitor-facing error template.

WordPress documents the distinction in its dead_db() reference, wpdb class reference, and require_wp_db() reference. PHP error-display settings are not a substitute: the wp-config.php handbook explains that database errors are handled by wpdb and are not affected by PHP error-reporting settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If the site still cannot connect to its database

The custom page changes only the error visitors see. To address a connection failure, follow WordPress’s common errors troubleshooting guidance:

  1. Check the database name, username, password, and host in wp-config.php against the values supplied by your hosting provider.
  2. If those values are correct, ask your host whether the database server is unavailable or the account has reached a database quota.
  3. Once the underlying issue is fixed, test that the site loads normally and that the custom error page is no longer being served for database failures.

Recovery Mode is a separate feature, not a database-connection recovery mechanism. WordPress describes it as a way to handle some fatal PHP errors during regular page loads, often involving a plugin, theme, or custom code; it is not activated for CRON or background tasks. See the Recovery Mode documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.