Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果需要,请使用esle PHP脚本检查Wordpress的数据库访问_Php_Html_Wordpress - Fatal编程技术网

如果需要,请使用esle PHP脚本检查Wordpress的数据库访问

如果需要,请使用esle PHP脚本检查Wordpress的数据库访问,php,html,wordpress,Php,Html,Wordpress,最近,我们的托管公司mysql出现了很多问题,这导致我们的Wordpress站点显示出无法连接到数据库,而不是Wordpress站点。我想在index.php脚本中添加一些代码,用于检查数据库连接的状态,如果连接失败,则加载一个简单的html文件。否则,如果数据库连接良好,index.php脚本将继续正常加载Wordpress。下面是Wordpress当前的index.php脚本 <?php /** * Front to the WordPress application. This f

最近,我们的托管公司mysql出现了很多问题,这导致我们的Wordpress站点显示出
无法连接到数据库
,而不是Wordpress站点。我想在
index.php
脚本中添加一些代码,用于检查数据库连接的状态,如果连接失败,则加载一个简单的html文件。否则,如果数据库连接良好,
index.php
脚本将继续正常加载Wordpress。下面是Wordpress当前的index.php脚本

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

当没有可用的数据库连接时,您可以自定义错误消息

只需创建一个文件名为“WP\u CONTENT\u DIR”的文件/db error.php'
。一旦连接不成功,这将
require\u once()
ed

如果文件不存在,将显示内置错误消息


参考源代码:

是的,这是正确的方法。你也可以很好地设计它来匹配你的网站。