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

'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();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?