I\'m trying to connect to an odbc database via php\'s PDO
class:
$dsn = \'odbc:CS_HDZipCodes32bit\';
$username = \'demo\';
$password = \'skdemo!
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.