【发布时间】:2021-03-26 01:49:21
【问题描述】:
我想在docker容器中运行php-fpm,但是启动容器后得到错误信息:
致命错误:未捕获的 PDOException:找不到驱动程序。
我在一个单独的容器中使用 php7.4 和事件引擎和一个 postgres 数据库(我使用 docker-compose 来启动它们)并且正在开发 ubuntu20.04。
奇怪的是:我的同事安装了同样的东西而没有出现这个错误,所以错误不可能来自不正确的 docker 文件。
到目前为止我尝试了什么:
- 我可以从 shell 使用 psql 连接到数据库。
- 我打印出了容器中加载的所有模块,它们包括
pdo和pdo_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.dns、pdo.user和pdo.pwd,它们都是正确的。我通过
DNS = "pgsql:host=HOSTNAME port=5432 dbname=DATABASENAME"
docker 文件包括
docker-php-ext-install pdo_pgsql
【问题讨论】:
标签: php postgresql docker pdo fpm