I'm trying to connect to an odbc database via php's PDO
class:
$dsn = 'odbc:CS_HDZipCodes32bit';
$username = 'demo';
$password = 'skdemo!';
$connection = new PDO($dsn, $username, $password);
die( var_dump( $connection ) );
but when I do, I get the error :
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:inetpubwwwrootpdoClass.php:7 Stack trace: #0 C:inetpubwwwrootpdoClass.php(7): PDO->__construct('odbc:CS_HDZipCo...', 'demo', 'skdemo!') #1 {main} thrown in C:inetpubwwwrootpdoClass.php on line 7
The $dsn
value is the name of the DSN I created in my ODBC Manager.
I know this particular DSN works because I was able to build another demo file and connect successfully via odbc_connect
:
$connection = odbc_connect("CS_HDZipCodes32bit", 'demo', 'skdemo!');
if(!$connection){
die('connection failed');
}
$statement = "SELECT * FROM ZipCodes";
$result = odbc_exec($connection, $statement);
// Outputs the zips as expected
var_dump(odbc_result_all($result));
I've been digging through the PDO-ODBC documentation as well as other resources online, but I can't figure out why PHP is unable to find the driver when trying from PDO.
Any ideas?
Update
I popped open my phpinfo page to make sure the odbc driver is installed per Marc B's comment:
It looks like the driver is installed unless this is a different driver.
Another Update
On further inspection of my phpini per Marc B's additional comment, it looks like I don't have the POD ODBC specific driver installed:
So here, if I had the ODBC driver for pdo installed, odbc
would be at the end of the list, correct?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…