Trying to connect to access database with PDO

会有一股神秘感。 提交于 2020-07-03 08:00:31

问题


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

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