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 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.
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: pdo_mysql, pdo_pgsql, pdo_sqliteInstall the driver in a Docker image
docker-php-ext-install pdo_mysql pdo_pgsql
php -r "var_dump(PDO::getAvailableDrivers());"Match the DSN to a loaded driver
- Run
PDO::getAvailableDrivers()to see which schemes are usable. - Confirm your DSN prefix (
mysql:/pgsql:/sqlite:) matches one of them. - Declare
ext-pdo_mysql(etc.) incomposer.jsonso 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 incomposer.json.