I have the following error -
Fatal error: Uncaught PDOException: could not find driver
When trying to connect via PDO.
<?php $host = '127.0.0.1'; $db = 'mytodo'; $user = 'root'; $pass = 'root'; $charset = 'utf8mb4'; $options = [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::ATTR_EMULATE_PREPARES => false, ]; $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; try { $pdo = new \PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { throw new \PDOException($e->getMessage(), (int)$e->getCode()); } require ('index.view.php');
I've experienced numerous instances of the same problem, all solved by uncommenting "extension=php_pdo_mysql.dll" in php.ini, but it made no difference to me.
I'm using Windows 10, MAMP and PHP 8.0.1
phpinfo() shows no driver under PDO
Although there is no comment in php.ini
Any help would be greatly appreciated
I'm not entirely sure if this is the right way to solve this problem, but it works, so I guess so?
It turns out that the location listed in the MAMP documentation was not the location I was looking for
C:\MAMP\conf\phpX.XX
- it was actuallyC:\MAMP\bin\php \phpX.X.X
. The problem I ran into after realizing this was that there was no php.ini file here, which is why I thought it was somewhere else. I then copied the .ini from theC:\MAMP\conf\phpX.XX
location and restarted MAMP. Prosperity.