Pdo Returning Error "Could Not Find Driver" with a Known Working Dsn

PDO returning error could not find driver with a known working DSN

After getting some great help from Marc B in the initial question's comments it turns out the problem was coming from my misunderstanding of enabling odbc on my web server and having the pdo_odbc driver installed.

While I did have odbc enabled on the web server, I did not have the odbc driver installed for PDO.

missing odbc driver

This driver is necessary to be able to access odbc databases via pdo.

Per the php.net documentation on installing pdo for windows, the driver was already included in the php build (I'm using version 5.5) and just needed to be included in the php.ini file.

including php_pdo.dll

After adding the driver and restarting the server I now had the driver loaded:

Sample Image

and my test query using PDO on my demo database worked:

$dsn = 'odbc:CS_HDZipCodes32bit';
$username = 'demo';
$password = 'skdemo!';

$connection = new PDO($dsn, $username, $password);

$query = "Select * FROM ZipCodes";

$result = $connection->query($query);

foreach($result as $row){
var_dump($row);
}

Dumps out:

pdo var dump

Thanks for your help Marc B.

Can't connect to odbc in php. could not find drivers

See if this situation helps you. It seems to be the same question.

PDO returning error “could not find driver” with a known working DSN

PDOException “could not find driver”

You need to have a module called pdo_mysql. Looking for following in phpinfo(),

pdo_mysql

PDO Driver for MySQL, client library version => 5.1.44

PDO : Uncaught PDOException: could not find driver

You need to enable those extensions in order to have ODBC PDO driver working

php_pdo.dll 
php_odbc.dll
php_pdo_odbc.dll

Could not find driver error for PDO ODBC connection when running PHP script on Windows command line

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() and php_ini_scanned_files() in both environments to see if this is your issue.

PDO object:could not find driver

If you just grabbed a copy of ttrss recently, it looks like Fox changed how the variables were being accessed in the configuration. Instead of using defined variables, it's now using environmental variables. For example

putenv('TTRSS_DB_TYPE=mysql');
putenv('TTRSS_DB_HOST=mydbhost');
putenv('TTRSS_DB_USER=trss');
putenv('TTRSS_DB_NAME=trss');
putenv('TTRSS_DB_PASS=supersecretpassword');

See https://git.tt-rss.org/fox/tt-rss/wiki/GlobalConfig and https://community.tt-rss.org/t/exception-while-creating-pdo-object-could-not-find-driver/4540

PDO sqlsrv: could not find driver

After I found the error log on the Windows Server, I solved the error by myself.

I got this error in my log:

[21-Apr-2017 07:12:14 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library '...\ext\php_pdo_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application. in Unknown on line 0

Then I downloaded again the driver and installed the x64-Driver. Finally It works without any problems.



Related Topics



Leave a reply



Submit