未捕获的 PDOException:即使有扩展也找不到驱动程序

Uncaught PDOException: could not find driver even when the extensions are there

另一个让我抓狂的错误。 我已经阅读了 Whosebug 中的 50 篇文章并尝试了所有不同的解决方案:

这是我在本地环境中使用的:

这是我的代码:

return new PDO('
    mysql:host='.Env::getInstance()->env('dbhost').';
    dbname='.Env::getInstance()->env('dbname'),
    Env::getInstance()->env('dbusername'),
    Env::getInstance()->env('dbpassword')
);

有什么我没试过的吗?我想一劳永逸地解决这个问题。

提前致谢。

传递给 PDO 构造函数的参数必须类似于下面 php 手册示例中的 $dsn。

<?php
/* Connect to a MySQL database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

?>

您的第一个参数似乎有错误的内容。