Timber
Timber

Reputation: 877

How can you tell which sql driver(s) are installed using PHP?

Forgive me if there are duplicate question elsewhere, but I can't find the answer anywhere!

Is there a way in PHP to show all sql drivers that are installed? For example check if I have oci, pdo, or mysqli on my webserver.

Upvotes: 1

Views: 6792

Answers (1)

BenMorel
BenMorel

Reputation: 36554

get_loaded_extensions() will give you all the extensions installed:

print_r(get_loaded_extensions());

You can filter the PDO ones that start with pdo_:

foreach (get_loaded_extensions() as $extension) {
    if (substr($extension, 0, 4) == 'pdo_') {
        echo $extension . PHP_EOL;
    }
}

Which gives the following result on my machine:

pdo_sqlite
pdo_mysql
pdo_pgsql

For the non-PDO extensions, you need to individually compare them against the list produced by get_loaded_extensions(), or query them using extension_loaded().

Upvotes: 5

Related Questions