Skip to content
Latchkey

PHP "could not find driver" - Missing PDO Driver in CI

PDO needs a database-specific driver extension (pdo_mysql, pdo_pgsql, pdo_sqlite) to talk to that database. When the driver is not loaded on the runner, constructing a PDO connection throws "could not find driver".

What this error means

A database connection in CI throws PDOException: could not find driver, even though the database service is reachable. php -m does not list the relevant pdo_* driver, though base PDO is present.

PHP error
PHP Fatal error:  Uncaught PDOException: could not find driver in
/app/src/Db.php:21
Stack trace:
#0 /app/src/Db.php(21): PDO->__construct('mysql:host=...')

Common causes

The pdo_* driver extension is not loaded

pdo_mysql for MySQL, pdo_pgsql for Postgres, pdo_sqlite for SQLite. Base pdo being present is not enough - the specific driver must be enabled.

Wrong DSN scheme for the loaded drivers

A mysql: DSN with only pdo_pgsql loaded still fails - PDO has no driver matching the DSN prefix.

How to fix it

Enable the right PDO driver in CI

List the database-specific driver on setup-php.

.github/workflows/ci.yml
- uses: shivammathur/setup-php@v2
  with:
    php-version: '8.3'
    extensions: pdo_mysql, pdo_pgsql, pdo_sqlite

Install the driver in a Docker image

Terminal
docker-php-ext-install pdo_mysql pdo_pgsql
php -r "var_dump(PDO::getAvailableDrivers());"

Match the DSN to a loaded driver

  1. Run PDO::getAvailableDrivers() to see which schemes are usable.
  2. Confirm your DSN prefix (mysql:/pgsql:/sqlite:) matches one of them.
  3. Declare ext-pdo_mysql (etc.) in composer.json so installs fail loudly.

How to prevent it

  • Enable the exact pdo_* driver your app uses in CI.
  • Assert drivers with PDO::getAvailableDrivers() early in the job.
  • Declare the driver as an ext-* requirement in composer.json.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →