wp在php7的机器上可能会因为没有php-mysql扩展而无法使用,想了一下,这问题应该不少人提出,应该有解决方法,无意间在wp-includes/wp-db.php中看到了这么一段话:
/** * Connects to the database server and selects a database * * PHP5 style constructor for compatibility with PHP5. Does * the actual setting up of the class properties and connection * to the database. * * @link https://core.trac.wordpress.org/ticket/3354 * @since 2.0.8 * * @global string $wp_version * * @param string $dbuser MySQL database user * @param string $dbpassword MySQL database password * @param string $dbname MySQL database name * @param string $dbhost MySQL database host */ public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { register_shutdown_function( array( $this, '__destruct' ) ); if ( WP_DEBUG && WP_DEBUG_DISPLAY ) $this->show_errors(); // Use ext/mysqli if it exists unless WP_USE_EXT_MYSQL is defined as true if ( function_exists( 'mysqli_connect' ) ) { $this->use_mysqli = true; if ( defined( 'WP_USE_EXT_MYSQL' ) ) { $this->use_mysqli = ! WP_USE_EXT_MYSQL; } }
于是明白了,在wp-config.php中定义一下就可以强制使用php-mysqli了:
define('WP_USE_EXT_MYSQL', False);
看了下鬼佬的解释(非官方),当机器安装了mysqli并且php版本>=5.5,或者这个常量未声明,则会自动使用mysqli。但我这确实遇到一个诡异的站点是自动选择mysql库,所以定义一下安心些。