Get the list of ODBC Data Sources using PHP from windows PC

0

How to get the list of all ODBC data sources available in my windows pc using PHP. I have tried using the below code. But getting empty. Could you please help.

    define('HKEY_LOCAL_MACHINE', 0x80000002); 
    $computer = '.'; 
    $reg = new COM("winmgmts:{impersonationLevel=impersonate}\\\\" . $computer . "\\root\\default:StdRegProv"); 

    $key_path = 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers'; 
    $sub_keys = array();
    $reg->EnumKey(HKEY_LOCAL_MACHINE, $key_path, $sub_keys); 

    foreach($sub_keys as $sub_key){ 
        echo $sub_key; 
    }
php
odbc
asked on Stack Overflow Apr 25, 2017 by Ba.Lal • edited Apr 26, 2017 by Ba.Lal

1 Answer

0

Finally I got the solution and its working fine.

    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"; 
    }
answered on Stack Overflow Apr 27, 2017 by Ba.Lal

User contributions licensed under CC BY-SA 3.0