返回介绍

dead_db()

发布于 2017-09-10 22:02:18 字数 2771 浏览 953 评论 0 收藏 0

dead_db()

Load custom DB error or display WordPress DB error.


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.


源代码

File: wp-includes/functions.php

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.
	status_header( 500 );
	nocache_headers();
	header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php _e( 'Database Error' ); ?></title>

</head>
<body>
	<h1><?php _e( 'Error establishing a database connection' ); ?></h1>
</body>
</html>
<?php
	die();
}

更新日志

Versiondescription
2.3.2Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_installing()
  • wp-includes/l10n.php: _e()
  • wp-includes/load.php: wp_load_translations_early()
  • wp-includes/functions.php: wp_die()
  • wp-includes/functions.php: status_header()
  • wp-includes/functions.php: nocache_headers()
  • wp-includes/l10n.php: is_rtl()
  • Show 2 more uses Hide more uses

Used By

  • wp-includes/load.php: wp_set_wpdb_vars()
  • wp-includes/functions.php: is_blog_installed()
  • wp-includes/ms-load.php: ms_not_installed()
  • wp-includes/wp-db.php: wpdb::check_connection()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文