Content · Web Development · PHP

PHP PDO::getAvailableDrivers() Method: Usage and Examples

Returns the names of PDO drivers installed in the current PHP runtime. The PDO extension alone does not install database-specific

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

Returns the names of PDO drivers installed in the current PHP runtime.

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

What It Does


Returns the names of PDO drivers installed in the current PHP runtime.

Syntax and Return Value


PDO::getAvailableDrivers(): mixed

The return value and exceptional cases depend on the call described here: The PDO extension alone does not install database-specific drivers.

Example 1: Basic Use


This self-contained SQLite example uses in-memory demo data; it requires the pdo_sqlite driver.

<?php
echo implode(", ", PDO::getAvailableDrivers());

Example 2: A Second Scenario


This self-contained SQLite example uses in-memory demo data; it requires the pdo_sqlite driver. This additional check distinguishes the method's result from connection or statement state.

<?php
echo implode(", ", PDO::getAvailableDrivers());
echo count(PDO::getAvailableDrivers());

Example 3: Practical Checks


This self-contained SQLite example uses in-memory demo data; it requires the pdo_sqlite driver. This additional check distinguishes the method's result from connection or statement state.

<?php
echo implode(", ", PDO::getAvailableDrivers());
echo in_array("sqlite", PDO::getAvailableDrivers(), true) ? "sqlite installed" : "sqlite unavailable";

Important Behavior and Edge Cases


The PDO extension alone does not install database-specific drivers.

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

Comparison with Related Approaches


ApproachImportant distinction
PDO::getAvailableDriversReturns the names of PDO drivers installed in the current PHP runtime.
Related API / patternpdo_drivers is the procedural equivalent.

Common Beginner Mistakes


MistakeCorrect approach
Assuming the happy path covers edge casesThe PDO extension alone does not install database-specific drivers.
Using a related API interchangeablypdo_drivers is the procedural equivalent.

Key Takeaways


  • Returns the names of PDO drivers installed in the current PHP runtime.
  • The PDO extension alone does not install database-specific drivers.
  • pdo_drivers is the procedural equivalent.

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.