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
| Approach | Important distinction |
|---|---|
| PDO::getAvailableDrivers | Returns the names of PDO drivers installed in the current PHP runtime. |
| Related API / pattern | pdo_drivers is the procedural equivalent. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Assuming the happy path covers edge cases | The PDO extension alone does not install database-specific drivers. |
| Using a related API interchangeably | pdo_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.