dead_db

函式
dead_db ( No parameters )
定義位置
相關方法
do_feed_rdf
引入
2.3.2
棄用
-

dead_db: 當一個資料庫查詢失敗時,這個函式被呼叫。它記錄一條錯誤資訊,並向使用者輸出一條資訊,指出查詢有問題。

載入自定義DB錯誤或顯示WordPress DB錯誤。

如果在wp-content目錄下存在一個名為db-error.php的檔案,那麼它將被載入而不是顯示WordPress DB錯誤。如果沒有找到它,那麼將顯示WordPress DB錯誤。

WordPress DB錯誤將HTTP狀態頭設定為500,以試圖防止搜尋引擎快取該資訊。自定義DB訊息也應該這樣做。

這個功能被回傳到WordPress 2.3.2,但最初是在WordPress 2.5.0中新增的。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function dead_db() {
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
require_once WP_CONTENT_DIR . '/db-error.php';
die();
}
// If installing or in the admin, provide the verbose message.
if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
wp_die( $wpdb->error );
}
// Otherwise, be terse.
wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
}
function dead_db() { global $wpdb; wp_load_translations_early(); // Load custom DB error template, if present. if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) { require_once WP_CONTENT_DIR . '/db-error.php'; die(); } // If installing or in the admin, provide the verbose message. if ( wp_installing() || defined( 'WP_ADMIN' ) ) { wp_die( $wpdb->error ); } // Otherwise, be terse. wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) ); }
function dead_db() {
	global $wpdb;

	wp_load_translations_early();

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

	// If installing or in the admin, provide the verbose message.
	if ( wp_installing() || defined( 'WP_ADMIN' ) ) {
		wp_die( $wpdb->error );
	}

	// Otherwise, be terse.
	wp_die( '<h1>' . __( 'Error establishing a database connection' ) . '</h1>', __( 'Database Error' ) );
}

常見問題

FAQs
檢視更多 >