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

佐手、 提交于 2019-11-27 14:45:14

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.

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.

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

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:

Thanks for your help Marc B.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!