drus39136 2017-07-24 21:08
浏览 753
已采纳

'Microsoft Access Driver(* .mdb)':找不到文件'错误连接pdo与php中的odbc

I am trying to connect the Microsoft access database using PDO with odbc. I have mounted the files on network drive and I am trying to access them, but I am getting the following error:

PDOException' with message 'SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb)'': file not found'.

Here is my code:

$dbName = "/info/new.mdb";

if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$database = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq= $dbName;Uid=admin");
  • 写回答

1条回答 默认 最新

  • duanpiangeng8958 2017-08-11 10:07
    关注

    First, make sure the odbc extension is activated in the php.ini file. Just remove the ; to enable it.

    ;extension=php_pdo_odbc.dll
    

    Then for connection, please use the exact file location with proper convention (it should be using backslash). The example is below.

    try {
        $file_location = "C:\Users\PC1\Desktop\your_database.mdb";
        $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_location;Uid=Admin");
    
        //Do your program stuffs here
    
        $dbh = null;
    } catch (PDOException $e){
        echo $e->getMessage();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名