PDO allows you to programmatically get the list of all installed drivers. The PDO::getAvailableDrivers()
method can be called to return an array containing the names of the database drivers that can be used. For example, this code will print something similar to the following:
var_dump(PDO::getAvailableDrivers()); array(3) { [0]=> string(5) "mysql" [1]=> string(6) "sqlite" [2]=> string(7) "sqlite2" }
The names of drivers, contained in this array, are the prefixes for the connection strings. Also, the same name is returned as the value of the PDO::ATTR_DRIVER_NAME
attribute.
Note
The PDO::getAvailableDrivers()
method returns the names of drivers that are registered with the PDO system in the php.ini
file. You may not be able to use all of these drivers on the local machine—for example, if the MySQL server is not running then the presence of a MySQL item in the returned array does not mean that you can connect to the local MySQL server, and if...