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:
- Type
which phpin the terminal to find out which PHP is being used on the local machine. - 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 - In this folder, look for the
php.inifile. If there are onlyphp.ini-developmentandphp.ini-productionfiles - rename one of these files tophp.ini. - Edit the
php.inifile. - Uncomment
;extension_dir = "ext"by removing the;at the beginning. - Uncomment
;extension=mysqli. - Save the file.
- Restart the terminal and try again.