4

Today I installed the latest version of WordPress and all went fine, except the fact that when I'm trying to config the database access. WordPress insists on using mysql_connect which is undefined in PHP versions above 5.X. I already tried setting wp-config by defining this:

define('WP_USE_EXT_MYSQL', false);

also tried setting it as true just for testing purposes, and nothing works.

Also, I already set up all extensions in PHP including mysqlnd and mysqli. Basically I did everything in stackoverflow and still I got nothing.

The following error is what is showing up:

PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in

I'm using PHP 7.4 and MySQL 8.0. Also, WordPress is in its latest version.

James Z
  • 12,209
  • 10
  • 24
  • 44
Gabryeu
  • 51
  • 3

1 Answers1

3

In Wordpress's source code, the condition for deciding to use mysqli or mysql is the following in wp-db.php:615, the variable $this->use_mysqli:

if ( function_exists( 'mysqli_connect' ) ) {
    $this->use_mysqli = true;

    if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
        $this->use_mysqli = ! WP_USE_EXT_MYSQL;
    }
}

If the function mysqli_connect existed, you'd be okay as the later if statement which decides to use between mysql_connect and mysqli_connect is in function db_connect() in wp-db.php:1630, simplified below:

if ( $this->use_mysqli ) {
  // [...]
  @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
}else{
  // [...]
  $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
}

I would say that the reason is that you don't have mysqli installed, is that possible?

Can you make sure you have the proper packages installed. On a debian machine, I would have to install the php-mysql package, e.g.

apt install php-mysql
Wadih M.
  • 12,810
  • 7
  • 47
  • 57