admin管理员组文章数量:1023204
I just upgraded to PHP 7 only to find that WordPress 4.8.1 (latest version) still uses mysql_connect in the wp-db.php module, but mysql_connect has been deprecated.
The following code is taken from wp-db-php, lines 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);
}
Here is the output when I try to run my program:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php:1570
Stack trace:
#0 D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php(658): wpdb->db_connect()
#1 D:\ApacheHtdocs\ConneXions\wp-includes\load.php(404): wpdb->__construct('root', '', 'connexions', 'localhost')
#2 D:\ApacheHtdocs\ConneXions\wp-settings.php(106): require_wp_db()
#3 D:\ApacheHtdocs\ConneXions\wp-config.php(104): require_once('D:\ApacheHtdocs...')
#4 D:\ApacheHtdocs\ConneXions\wp-load.php(37): require_once('D:\ApacheHtdocs...')
#5 D:\ApacheHtdocs\ConneXions\wp-blog-header.php(13): require_once('D:\ApacheHtdocs...')
#6 D:\ApacheHtdocs\ConneXions\index.php(17): require('D:\ApacheHtdocs...')
#7 {main} thrown in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php on line 1570
I can't believe that WordPress says it recommends PHP 7, but it doesn't work with it. What am I missing here?
I just upgraded to PHP 7 only to find that WordPress 4.8.1 (latest version) still uses mysql_connect in the wp-db.php module, but mysql_connect has been deprecated.
The following code is taken from wp-db-php, lines 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);
}
Here is the output when I try to run my program:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php:1570
Stack trace:
#0 D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php(658): wpdb->db_connect()
#1 D:\ApacheHtdocs\ConneXions\wp-includes\load.php(404): wpdb->__construct('root', '', 'connexions', 'localhost')
#2 D:\ApacheHtdocs\ConneXions\wp-settings.php(106): require_wp_db()
#3 D:\ApacheHtdocs\ConneXions\wp-config.php(104): require_once('D:\ApacheHtdocs...')
#4 D:\ApacheHtdocs\ConneXions\wp-load.php(37): require_once('D:\ApacheHtdocs...')
#5 D:\ApacheHtdocs\ConneXions\wp-blog-header.php(13): require_once('D:\ApacheHtdocs...')
#6 D:\ApacheHtdocs\ConneXions\index.php(17): require('D:\ApacheHtdocs...')
#7 {main} thrown in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php on line 1570
I can't believe that WordPress says it recommends PHP 7, but it doesn't work with it. What am I missing here?
Share Improve this question edited Aug 6, 2017 at 0:51 Peter Mortensen 2682 silver badges10 bronze badges asked Aug 5, 2017 at 19:58 Bob JonesBob Jones 4331 gold badge5 silver badges10 bronze badges 1 |4 Answers
Reset to default 10This sounds like you do not have mysqli installed and/or enabled on your server. IIRC mysqli
was added to php in version 5.5, and the older mysql
extension had been deprecated and fully retired since then. If you upgraded from a very old PHP version it might be that you still need the extra step of enabling mysqli
.
(wordpress checks for the existence of mysqli
and only if it does not exist tries the older mysql
functions.)
In addition to @MarkKaplun answer, I post some code from the wpdb class:
Here's how the wpdb::use_mysqli
is determined:
It's initalized with:
/**
* Whether to use mysqli over mysql.
*
* @since 3.9.0
* @access private
* @var bool
*/
private $use_mysqli = false;
and then in the wpdb
constructor we have:
/* 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;
}
}
What you should do to solve this problem, is to edit your php.ini file.
run where is php.ini
I found mine at:
/etc/php/php.ini
(although I don't know what OS you are running simple find yours)
Look for these two files:
extension=pdo_mysql.so
extension=mysqli.so
and uncomment them. Voila, that would get the job done anytime.
Further reading: https://wiki.archlinux/index.php/PHP
Are you using Xamppp 7.x for Windows?
It happened to me when I upgraded my Xampp 5.6 to Xampp 7.1. Inspecting the configuration file C:\Xampp\php\php.ini, I noticed a lot of errors involving the name of PHP extensions (they lack the prefix php_ and the suffix .dll). One of them is related to mysqli.
The wrong setting I found there:
extension=mysqli
The right setting (after editing this line):
extension=php_mysqli.dll
Correcting that solved my problem.
By the way: don't forget to correct all other wrong settings (the correct name of the extensions can be seen at C:\xampp\php\ext).
I just upgraded to PHP 7 only to find that WordPress 4.8.1 (latest version) still uses mysql_connect in the wp-db.php module, but mysql_connect has been deprecated.
The following code is taken from wp-db-php, lines 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);
}
Here is the output when I try to run my program:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php:1570
Stack trace:
#0 D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php(658): wpdb->db_connect()
#1 D:\ApacheHtdocs\ConneXions\wp-includes\load.php(404): wpdb->__construct('root', '', 'connexions', 'localhost')
#2 D:\ApacheHtdocs\ConneXions\wp-settings.php(106): require_wp_db()
#3 D:\ApacheHtdocs\ConneXions\wp-config.php(104): require_once('D:\ApacheHtdocs...')
#4 D:\ApacheHtdocs\ConneXions\wp-load.php(37): require_once('D:\ApacheHtdocs...')
#5 D:\ApacheHtdocs\ConneXions\wp-blog-header.php(13): require_once('D:\ApacheHtdocs...')
#6 D:\ApacheHtdocs\ConneXions\index.php(17): require('D:\ApacheHtdocs...')
#7 {main} thrown in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php on line 1570
I can't believe that WordPress says it recommends PHP 7, but it doesn't work with it. What am I missing here?
I just upgraded to PHP 7 only to find that WordPress 4.8.1 (latest version) still uses mysql_connect in the wp-db.php module, but mysql_connect has been deprecated.
The following code is taken from wp-db-php, lines 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);
}
Here is the output when I try to run my program:
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php:1570
Stack trace:
#0 D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php(658): wpdb->db_connect()
#1 D:\ApacheHtdocs\ConneXions\wp-includes\load.php(404): wpdb->__construct('root', '', 'connexions', 'localhost')
#2 D:\ApacheHtdocs\ConneXions\wp-settings.php(106): require_wp_db()
#3 D:\ApacheHtdocs\ConneXions\wp-config.php(104): require_once('D:\ApacheHtdocs...')
#4 D:\ApacheHtdocs\ConneXions\wp-load.php(37): require_once('D:\ApacheHtdocs...')
#5 D:\ApacheHtdocs\ConneXions\wp-blog-header.php(13): require_once('D:\ApacheHtdocs...')
#6 D:\ApacheHtdocs\ConneXions\index.php(17): require('D:\ApacheHtdocs...')
#7 {main} thrown in D:\ApacheHtdocs\ConneXions\wp-includes\wp-db.php on line 1570
I can't believe that WordPress says it recommends PHP 7, but it doesn't work with it. What am I missing here?
Share Improve this question edited Aug 6, 2017 at 0:51 Peter Mortensen 2682 silver badges10 bronze badges asked Aug 5, 2017 at 19:58 Bob JonesBob Jones 4331 gold badge5 silver badges10 bronze badges 1-
2
mysql_connect
is only used as a fallback whenmysqli
is not detected. It would appear you have neithermysqli
ormysql
installed (mysqli
is recommended,mysql
is deprecated ) – Tom J Nowell ♦ Commented Aug 5, 2017 at 21:26
4 Answers
Reset to default 10This sounds like you do not have mysqli installed and/or enabled on your server. IIRC mysqli
was added to php in version 5.5, and the older mysql
extension had been deprecated and fully retired since then. If you upgraded from a very old PHP version it might be that you still need the extra step of enabling mysqli
.
(wordpress checks for the existence of mysqli
and only if it does not exist tries the older mysql
functions.)
In addition to @MarkKaplun answer, I post some code from the wpdb class:
Here's how the wpdb::use_mysqli
is determined:
It's initalized with:
/**
* Whether to use mysqli over mysql.
*
* @since 3.9.0
* @access private
* @var bool
*/
private $use_mysqli = false;
and then in the wpdb
constructor we have:
/* 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;
}
}
What you should do to solve this problem, is to edit your php.ini file.
run where is php.ini
I found mine at:
/etc/php/php.ini
(although I don't know what OS you are running simple find yours)
Look for these two files:
extension=pdo_mysql.so
extension=mysqli.so
and uncomment them. Voila, that would get the job done anytime.
Further reading: https://wiki.archlinux/index.php/PHP
Are you using Xamppp 7.x for Windows?
It happened to me when I upgraded my Xampp 5.6 to Xampp 7.1. Inspecting the configuration file C:\Xampp\php\php.ini, I noticed a lot of errors involving the name of PHP extensions (they lack the prefix php_ and the suffix .dll). One of them is related to mysqli.
The wrong setting I found there:
extension=mysqli
The right setting (after editing this line):
extension=php_mysqli.dll
Correcting that solved my problem.
By the way: don't forget to correct all other wrong settings (the correct name of the extensions can be seen at C:\xampp\php\ext).
本文标签: wpdbWordPress 481 uses mysqlconnect which doesn39t work with PHP 7
版权声明:本文标题:wpdb - WordPress 4.8.1 uses mysql_connect which doesn't work with PHP 7 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745530145a2154711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
mysql_connect
is only used as a fallback whenmysqli
is not detected. It would appear you have neithermysqli
ormysql
installed (mysqli
is recommended,mysql
is deprecated ) – Tom J Nowell ♦ Commented Aug 5, 2017 at 21:26