2017-07-24 21:08
浏览 454

'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");

图片转代码服务由CSDN问答提供 功能建议

我正在尝试使用PDO和odbc连接Microsoft访问数据库。 我已将文件挂载到网络驱动器上,我正在尝试访问它们,但是我收到以下错误:

PDOException',消息为'SQLSTATE [01000] SQLDriverConnect :0 [unixODBC] [驱动程序管理器]无法打开lib'Microsoft Access驱动程序(* .mdb)'':找不到文件'。

这是 我的代码:

  $ dbName =“/ info / news.mdb”; 
nnnif(!file_exists($ dbName)){
 die(“找不到 数据库文件。“); 
 $ 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.


    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();
    点赞 打赏 评论

相关推荐 更多相似问题