"PDOException: could not find driver"存在于 PDO 模块的 docker 容器内



我想在docker容器中运行php-fpm,但在启动容器后收到一条错误消息:

致命错误:未捕获的PDOException:找不到驱动程序。

我在一个单独的容器中使用带有事件引擎和postgres数据库的php7.4(我使用docker compose来启动它们(,并且正在开发ubuntu20.4。

奇怪的是:我的同事安装了同样的东西,但没有出现这个错误,所以错误不可能来自错误的docker文件

到目前为止我尝试了什么:

  • 我可以从shell使用psql连接到数据库
  • 我打印出了容器中加载的所有模块,它们包括pdopdo_pgsql

错误指的是这种方法:

public function pdoConnection(): PDO
{
/** @var PDO $pdo */
$pdo = $this->makeSingleton(PDO::class, function () {
$this->assertMandatoryConfigExists('pdo.dsn');
$this->assertMandatoryConfigExists('pdo.user');
$this->assertMandatoryConfigExists('pdo.pwd');
return new PDO(
$this->config()->stringValue('pdo.dsn'),
$this->config()->stringValue('pdo.user'),
$this->config()->stringValue('pdo.pwd'),
[
// the next line is the line the error message refers to
PDO::ATTR_PERSISTENT => true,
// This is necessary due to the way pgBouncer handles (or not handles) prepared statements.
// See https://www.pgbouncer.org/faq.html#how-to-use-prepared-statements-with-transaction-pooling
PDO::ATTR_EMULATE_PREPARES => true,
]
);
});
return $pdo;
}

我检查了pdo.dnspdo.userpdo.pwd,它们都是正确的。我通过定义了DNS

DNS = "pgsql:host=HOSTNAME port=5432 dbname=DATABASENAME"

docker文件包括

docker-php-ext-install pdo_pgsql

在docker文件中尝试添加以下代码:

docker-php-ext-install 
pdo_pgsql

希望能帮助你。

这是DNS字符串,引号是错误的。它的工作原理是:

DNS = pgsql:host=HOSTNAME;port=5432;dbname=DATABASENAME

最新更新