简体   繁体   中英

How can I detect MDB2 installed drivers in PHP?

I'm trying to detect which MDB2 drivers are installed. That way I can use whatever the user installed. I tried using class_exists("MDB2_Driver_$driver", FALSE) or (@include_once("MDB2/Driver/$driver.php")), it does not work. (first one returns FALSE for all drivers, second one crashes for existing drivers)

Any ideas on how to do that? It seems that MDB2 does not include any methods for this.

If these are installed via PEAR, the following code will do the trick. It works by querying the PEAR registry to determine if the driver packages were installed. It will also display the version of each of those drivers.

require 'PEAR/Registry.php';
$reg = new PEAR_Registry;  
$drivers = array (       
    'MDB2_Driver_fbsql',
    'MDB2_Driver_ibase',
    'MDB2_Driver_mssql',
    'MDB2_Driver_mysql',   
    'MDB2_Driver_mysqli',  
    'MDB2_Driver_oci8',
    'MDB2_Driver_odbc',
    'MDB2_Driver_pgsql',
    'MDB2_Driver_querysim',
    'MDB2_Driver_sqlite',  
    'MDB2_Driver_sqlsrv',
);
foreach ($drivers as $driver) {
    $pkg = $reg->getPackage($driver);
    if (!is_null($pkg)) {  
        $version = $pkg->getVersion();
        echo "$driver v$version installed\n";
    }
}

This is based on a snippet of code I posted to https://gist.github.com/kenguest/1671361 last year.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM