尝试使用PDO连接访问数据库 [英] Trying to connect to access database with PDO

查看:88
本文介绍了尝试使用PDO连接访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到c驱动器上具有的访问数据库.我取消对INI文件中的访问扩展名pdo的注释.我运行了驱动程序测试,它显示odbc驱动程序已安装.我在Apache服务器上使用了Wamp,但我不断收到此错误

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驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序

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();
    }
    ?>

推荐答案

尝试以这种方式进行应该可以.

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();
}
?>

这篇关于尝试使用PDO连接访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆