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?

  • 2
    mysql_connect is only used as a fallback when mysqli is not detected. It would appear you have neither mysqli or mysql installed ( mysqli is recommended, mysql is deprecated )
    – Tom J Nowell
    Aug 5, 2017 at 21:26

4 Answers 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.)

  • mysql was part of PHP in versions 4 & 5, and removed in version 7. mysqli was introduced in PHP 5.0.0 and works in all PHP 5 versions and so far in all PHP 7 versions. You're probably thinking that mysql was deprecated in PHP 5.5.0.
    – CJ Dennis
    Aug 6, 2017 at 1:24
  • @CJDennis, that ia exactly what I said regarding the deprecation. If you think there is a mistake in my english, you are more then welcome to edit the answer ;) Aug 6, 2017 at 3:33
  • I was correcting your thought that mysqli was introduced in 5.5.0, when it was introduced in 5.0.0.
    – CJ Dennis
    Aug 6, 2017 at 3:36

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:


and uncomment them. Voila, that would get the job done anytime.

Further reading: https://wiki.archlinux.org/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:


The right setting (after editing this line):


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.