Problem

When using the command line interface for WordPress (WP-CLI), I got the following error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in site\wp-includes\class-wpdb.php:1807

Solution

Enabling the mysqli extension in php.ini solved this issue for me.

This is how I did it:

  1. Type which php in the terminal to find out which PHP is being used on the local machine.
  2. According to the path you got, open the file explorer and navigate to the folder where php.exe is located. I use “Local WP” to run the local PHP environment so this folder was something like: C:\Users\your.user\AppData\Roaming\Local\lightning-services\php-7.4.30+5\bin\win64
  3. In this folder, look for the php.ini file. If there are only php.ini-development and php.ini-production files - rename one of these files to php.ini.
  4. Edit the php.ini file.
  5. Uncomment ;extension_dir = "ext" by removing the ; at the beginning.
  6. Uncomment ;extension=mysqli.
  7. Save the file.
  8. Restart the terminal and try again.