Windows MAMP PHP encountered fatal error: Uncaught PDOException: Driver not found. The PHP.ini file has correctly uncommented sections
P粉274161593
P粉274161593 2024-03-27 16:18:23
0
1
457

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粉274161593
P粉274161593

reply all(1)
P粉795311321

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template