我刚刚升级到PHP 7,却发现WordPress 4.8.1(最新版本)仍然在wp db中使用mysql\\u connect。php模块,但mysql\\u connect已被弃用。
以下代码摘自wp db php,第1567-1571行:
if ( WP_DEBUG ) {
$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
} else {
$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this>dbpassword,
$new_link, $client_flags);
}
以下是我尝试运行程序时的输出:
致命错误:未捕获错误:调用D:\\ApacheHtdocs\\ConneXions\\wp includes\\wp db中未定义的函数mysql\\u connect()。php:1570堆栈跟踪:0 D:\\ApacheHtdocs\\ConneXions\\wp includes\\wp db。php(658):wpdb->db\\u connect()
1 D:\\ApacheHtdocs\\ConneXions\\wp includes\\load。php(404):wpdb->\\u构造(\'root\',\'\',\'\',\'connexions\',\'localhost\')
\\2 D:\\ApacheHtdocs\\connexions\\wp设置。php(106):需要\\u wp\\u db()
\\3 D:\\ApacheHtdocs\\ConneXions\\wp config。php(104):require\\u once(\'D:\\ApacheHtdocs…\')
\\4 D:\\ApacheHtdocs\\ConneXions\\wp load。php(37):require\\u once(\'D:\\ApacheHtdocs…\')
\\5 D:\\ApacheHtdocs\\ConneXions\\wp blog header。php(13):require\\u once(\'D:\\ApacheHtdocs…\')
\\6 D:\\ApacheHtdocs\\ConneXions\\index。php(17):在D:\\ApacheHtdocs\\ConneXions\\wp includes\\wp db中抛出require(\'D:\\ApacheHtdocs…\')
#7{main}。php在线1570
我不敢相信WordPress说它推荐PHP 7,但它不适用。我错过了什么?
SO网友:birgire
除了@MarkKaplun answer之外,我还发布了wpdb类中的一些代码:
以下是wpdb::use_mysqli
已确定:
它的初始值为:
/**
* Whether to use mysqli over mysql.
*
* @since 3.9.0
* @access private
* @var bool
*/
private $use_mysqli = false;
然后在
wpdb
我们的建造师:
/* Use ext/mysqli if it exists and:
* - WP_USE_EXT_MYSQL is defined as false, or
* - We are a development version of WordPress, or
* - We are running PHP 5.5 or greater, or
* - ext/mysql is not loaded.
*/
if ( function_exists( \'mysqli_connect\' ) ) {
if ( defined( \'WP_USE_EXT_MYSQL\' ) ) {
$this->use_mysqli = ! WP_USE_EXT_MYSQL;
} elseif ( version_compare( phpversion(), \'5.5\', \'>=\' ) || ! function_exists( \'mysql_connect\' ) ) {
$this->use_mysqli = true;
} elseif ( false !== strpos( $GLOBALS[\'wp_version\'], \'-\' ) ) {
$this->use_mysqli = true;
}
}