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

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

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

这是 我的代码: p>

  $ dbName =“/ info / news.mdb”; 
nnnif(!file_exists($ dbName)){
 die(“找不到 数据库文件。“); 
} 
 $ database = new PDO(”odbc:Driver = {Microsoft Access Driver(* .mdb)}; Dbq = $ dbName; Uid = admin“); 
  code>   pre> 
  div>

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