Like the title says I am getting an error when I try to run a php script via the windows command prompt i receive a “Could not find driver”.
When I run run this page through a browser via WAMP server NO errors are produced and the script runs fine. This ONLY happens when I run the script via the command prompt.
The database I am trying to connect to is on SQL Server 2008.
In the script I have the following code producing the error:
$user = 'MyUsername';
$pass = 'MyPass';
try {
$sql = new PDO('odbc:MyDB', $user, $pass);
} catch (PDOException $e) {
echo 'SQL Connection failed: ' . $e->getMessage();
}
I can’t speak to WAMP, but it’s possible that PHP is using different INI files for the web and command line environments, and that the INI file for the command line environment isn’t loading the pdo_odbc extension and the INI file for the web environment is loading it. Check the return values of
php_ini_loaded_file()andphp_ini_scanned_files()in both environments to see if this is your issue.