get list of ODBC data source in local pc using PHP
I'm looking for a way to get a li开发者_如何学Cst of ODBC data sources in local PC using PHP. How can I achieve that?
If I assume that you're running on windows
User defined ODBC connections are stored under HKEY_CURRENT_USER\Software\ODBC\ODBC.INI
System defined ODBC connections are stored under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI
ODBC drivers are defined under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI
So you need some trick with php to read from registry like this one or this one
If I assume that you are on unix/linux then
User defined ODBC connections are stored under /etc/odbc.ini
System defined ODBC connections are stored under /home/username/.odbc.ini
ODBC drivers are defined under /etc/odbcinst.ini
All of them are INI-like syntax text files.
PHP has built-in connection support for MySQL so a ODBC connection is not required. ODBC would be needed for any database environment not supported by PHP.
define('HKEY_LOCAL_MACHINE', 0x80000002);
$computer = '.';
$reg = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\$computer\\root\\default:StdRegProv");
$key_path = 'SOFTWARE\ODBC\ODBCINST.INI';
$sub_keys = new VARIANT();
$reg->EnumKey(HKEY_LOCAL_MACHINE, $key_path, $sub_keys);
foreach($sub_keys as $sub_key){
echo $sub_key . "\n";
}
精彩评论