Error with PDO and MySql: Could not find driver even when I enable it in the php.ini

70 Views Asked by At

I've tried to connect to my database using basic code and error checking but when I try it gives this error :

Could not find driver"

even when I enable extension=pdo_mysql.

By the way, when I do phpInfo(); it says that I'm on 8.0.30 if this can help.

Also, it says that the pdo drivers has novalue. Could it be because of the fact that the client api version is 8.3.4 and not 8.0 like php ?

2

There are 2 best solutions below

1
kabix 09 On

Make sure you have the pdo_mysql library installed in your PHP ext/ folder. If it exists, you may have a typo in your php.ini file (you need to uncomment extension=pdo_mysql). Otherwise, you might first need to install the appropriate PDO database drivers.

You can try list your extensions using php -m to ensure that PHP detects the library.

3
MichaelKre On

You can also try the following command to ensure library is loaded and enabled.

php --ri pdo_mysql

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 8.2.7

otherwise:

php --ri pdo_mysql
Extension 'pdo_mysql' not present.