简体   繁体   English

如何在PHP中检测MDB2安装的驱动程序?

[英]How can I detect MDB2 installed drivers in PHP?

I'm trying to detect which MDB2 drivers are installed. 我正在尝试检测安装了哪些MDB2驱动程序。 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. 我尝试使用class_exists(“ MDB2_Driver_ $ driver”,FALSE)或(@include_once(“ MDB2 / Driver / $ driver.php”)),它无法正常工作。 (first one returns FALSE for all drivers, second one crashes for existing drivers) (第一个对所有驱动程序返回FALSE,第二个对现有驱动程序崩溃)

Any ideas on how to do that? 关于如何做到这一点的任何想法? It seems that MDB2 does not include any methods for this. 看来MDB2对此不包含任何方法。

If these are installed via PEAR, the following code will do the trick. 如果这些是通过PEAR安装的,则下面的代码可以解决问题。 It works by querying the PEAR registry to determine if the driver packages were installed. 它通过查询PEAR注册表来确定是否安装了驱动程序包而工作。 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. 这是基于我去年发布到https://gist.github.com/kenguest/1671361的一小段代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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