"PDOException: could not find driver" 在 docker 容器内,其中存在 PDO 模块
"PDOException: could not find driver" inside docker container where PDO modules exist
我想在docker容器中运行 php-fpm,但是启动容器后出现错误信息:
Fatal error: Uncaught PDOException: could not find driver.
我在单独的容器中使用 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
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
我想在docker容器中运行 php-fpm,但是启动容器后出现错误信息:
Fatal error: Uncaught PDOException: could not find driver.
我在单独的容器中使用 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
在您的 docker 文件中尝试添加以下代码:
docker-php-ext-install \
pdo_pgsql
希望对你有帮助。
是DNS字符串,引号不对。它适用于:
DNS = pgsql:host=HOSTNAME;port=5432;dbname=DATABASENAME