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?

4 s
4

This 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.)

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *