dead_db

Load custom DB error or display WordPress DB error.

Description

dead_db(); 

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.


Usage

  1. if ( !function_exists( 'dead_db' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = dead_db(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function dead_db() { 
  2. global $wpdb; 
  3.  
  4.  
  5. // Load custom DBerrortemplate, if present. 
  6. if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { 
  7. require_once( WP_CONTENT_DIR . '/db-error.php' ); 
  8. die(); 
  9.  
  10. // If installing or in the admin, provide the verbose message. 
  11. if ( wp_installing() || defined( 'WP_ADMIN' ) ) 
  12. wp_die($wpdb->error); 
  13.  
  14. // Otherwise, be terse. 
  15. status_header( 500 ); 
  16. header( 'Content-Type: text/html; charset=utf-8' ); 
  17. ?> 
  18. <!DOCTYPE html> 
  19. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> 
  20. <head> 
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  22. <title><?php _e( 'Database Error' ); ?></title> 
  23.  
  24. </head> 
  25. <body> 
  26. <h1><?php _e( 'Error establishing a database connection' ); ?></h1> 
  27. </body> 
  28. </html> 
  29. <?php 
  30. die();