Content · Web Development · PHP

PHP pdo_drivers() Function: Usage and Examples

Returns PDO driver names available to the running PHP process. The list can be empty even when the PDO base extension is

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

Returns PDO driver names available to the running PHP process.

The objective is to understand the behavior and operational limits, not only the method name.

What It Does


Returns PDO driver names available to the running PHP process.

Syntax and Return Value


pdo_drivers(...)

The return value and exceptional cases depend on the call described here: The list can be empty even when the PDO base extension is installed.

Example 1: Basic Use


pdo_drivers() returns only installed PDO-specific drivers, not drivers installable on the server.

<?php
echo json_encode(pdo_drivers());

Example 2: A Second Scenario


pdo_drivers() returns only installed PDO-specific drivers, not drivers installable on the server. This additional check distinguishes the method's result from connection or statement state.

<?php
echo json_encode(pdo_drivers());
echo count(pdo_drivers());

Example 3: Practical Checks


pdo_drivers() returns only installed PDO-specific drivers, not drivers installable on the server. This additional check distinguishes the method's result from connection or statement state.

<?php
echo json_encode(pdo_drivers());
echo in_array("mysql", pdo_drivers(), true) ? "MySQL PDO installed" : "MySQL PDO absent";

Important Behavior and Edge Cases


The list can be empty even when the PDO base extension is installed.

For production use, also account for error handling, data validation, resource limits and environment-specific driver behavior.

Comparison with Related Approaches


ApproachImportant distinction
pdo_driversReturns PDO driver names available to the running PHP process.
Related API / patternPDO::getAvailableDrivers provides the equivalent static method.

Common Beginner Mistakes


MistakeCorrect approach
Assuming the happy path covers edge casesThe list can be empty even when the PDO base extension is installed.
Using a related API interchangeablyPDO::getAvailableDrivers provides the equivalent static method.

Key Takeaways


  • Returns PDO driver names available to the running PHP process.
  • The list can be empty even when the PDO base extension is installed.
  • PDO::getAvailableDrivers provides the equivalent static method.

Choose this API or pattern when its exact semantics match your task, and verify the result against the database driver and runtime used by your application.

Share this resourceSend this page to someone who may find it useful.