There are several Databases that PDO can connect to but they all require a different connection method.
$conn = new PDO("pgsql:host=localhost port=5432 dbname=pdo", "username", "password");
$conn = new PDO("informix:DSN=InformixDB", "username", "password");
$conn = new PDO("OCI:dbname=accounts;charset=UTF-8", "username", "password")w
PDO("sqlite:/path/to/database.sdb");
I am making a widget that will not know if the user is using a sql, SQlite, oracle or informix database but i want everything to be covered.
Question: Is there a way to check which database is available using PDO or should i just use PHP to ask which Databases are available and tell the PDO which one is being used from there?
This check will only be performed once so it isn’t extremely important that it is efficient but i would hope it is somewhat light weight.
any examples will be much appreciated as i am a novice and would enjoy a starting point.
You can use
PDO::getAvailableDrivers()to get a list of what is on the system.You will still need to build the connection string yourself (as all drivers can use wildly different parameters), but this will at least tell you what you can use on the system.