search

Home  >  Q&A  >  body text

Windows MAMP PHP encountered fatal error: Uncaught PDOException: Driver not found. The PHP.ini file has correctly uncommented sections

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

P粉274161593P粉274161593250 days ago454

reply all(1)I'll reply

  • P粉795311321

    P粉7953113212024-03-28 12:09:11

    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 actually C:\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 the C:\MAMP\conf\phpX.XX location and restarted MAMP. Prosperity.

    reply
    0
  • Cancelreply