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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?