问题
I am trying to connect to access database that I have on the c drive. I uncommented access extension pdo in INI file. I ran the driver test and it shows odbc driver is installed. I am using wamp with apache server but I keep getting this error
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
<?php
try {
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\staffing.mdb;Uid=Admin");
}
catch (PDOException $e) {
echo $e->getMessage();
}
?>
回答1:
Try doing it this way should work.
<?php
try {
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\\staffing.mdb;Uid=Admin");
}
catch (PDOException $e) {
echo $e->getMessage();
}
?>
来源:https://stackoverflow.com/questions/26858847/trying-to-connect-to-access-database-with-pdo