diff --git a/wp-includes/functions.php b/wp-includes/functions.php index dca06c3610..a2a5fb4f85 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1529,6 +1529,37 @@ function require_wp_db() { require_once( ABSPATH . WPINC . '/wp-db.php' ); } +function dead_db() { + global $wpdb; + + // Load custom DB error template, if present. + if ( file_exists( ABSPATH . 'wp-content/db-error.php' ) ) { + require_once( ABSPATH . 'wp-content/db-error.php' ); + die(); + } + + // If installing or in the admin, provide the verbose message. + if ( defined('WP_INSTALLING') || defined('WP_ADMIN') ) + wp_die($wpdb->error); + + // Otherwise, be terse. + status_header( 500 ); + nocache_headers(); + header( 'Content-Type: text/html; charset=utf-8' ); +?> + +> + + Database Error + + + +

Error establishing a database connection

+ + + diff --git a/wp-settings.php b/wp-settings.php index 96131f2243..2d40b4a935 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -196,6 +196,10 @@ require (ABSPATH . WPINC . '/functions.php'); require (ABSPATH . WPINC . '/classes.php'); require_wp_db(); + +if ( !empty($wpdb->error) ) + dead_db(); + $prefix = $wpdb->set_prefix($table_prefix); if ( is_wp_error($prefix) )