Load custom DB error or display WordPress DB error.

Description Description

If a file exists in the wp-content directory named db-error.php, then it will be loaded instead of displaying the WordPress DB error. If it is not found, then the WordPress DB error will be displayed instead.

The WordPress DB error sets the HTTP status header to 500 to try to prevent search engines from caching the message. Custom DB messages should do the same.

This function was backported to WordPress 2.3.2, but originally was added in WordPress 2.5.0.

Source Source

File: wp-includes/functions.php

function dead_db() {
	global $wpdb;


	// Load custom DB error template, if present.
	if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
		require_once( WP_CONTENT_DIR . '/db-error.php' );

	// If installing or in the admin, provide the verbose message.
	if ( wp_installing() || defined( 'WP_ADMIN' ) )

	// Otherwise, be terse.
	status_header( 500 );
	header( 'Content-Type: text/html; charset=utf-8' );
<!DOCTYPE html>
<html xmlns=""<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php _e( 'Database Error' ); ?></title>

	<h1><?php _e( 'Error establishing a database connection' ); ?></h1>

Top ↑

Changelog Changelog

Version Description
2.3.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.