I want to run php-fpm in a docker container, but get an error message after starting the container:
Fatal error: Uncaught PDOException: could not find driver.
I use php7.4 with event engine and a postgres database in a separate container (I use docker-compose to start them all) and are working on ubuntu20.04.
The weird thing is: My collegues installed the same stuff without having this error, so the error cannot come from an incorrect docker file.
What I tried so far:
- I can connect to the database with psql from the shell.
- I printed out all modules that are loaded in the container, and they include
pdo
andpdo_pgsql
.
The error refers to this method:
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; }
I checked pdo.dns
, pdo.user
and pdo.pwd
, they are all correct. I defined DNS via
DNS = "pgsql:host=HOSTNAME port=5432 dbname=DATABASENAME"
The docker file includes
docker-php-ext-install pdo_pgsql
Advertisement
Answer
It was the DNS string, the quotation marks are wrong. It works with this:
DNS = pgsql:host=HOSTNAME;port=5432;dbname=DATABASENAME