PHP pdo ODBC 和 mdb 文件驱动程序

PHP pdo ODBC and mdb file driver

我 PHP 5.5 Windows 7 。我正在尝试使用 PHP 访问名为 main.mdb 的 MS Access 数据库文件。我正在使用以下代码:

<?php
$dbName = "C:\test\main.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
// The following is line 7
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)};charset=UTF-8; DBQ=$dbName; Uid=; Pwd=;");
//$db->exec("set names windows-1256");
$sql = "SELECT 0bok.*, `0cat`.name FROM 0bok INNER JOIN 0cat ON `0cat`.id = `0bok`.cat WHERE cat = 35 OR cat = 38 OR cat = 39 OR cat = 41 OR cat = 47 OR cat = 48 OR cat = 4 OR cat = 5 ORDER BY cat";
$result = $db->query($sql);
$row = $result->fetchAll();
$i = 1;

echo "<pre>";
foreach ($row as $book) {
    echo $i . ": " . iconv("windows-1256", "utf-8", $book['bk']) . ", " . $book['bkid'] . " -> " . iconv("windows-1256", "utf-8", $book['name'])  . "\n";
    $i++;
}

但是,我收到以下错误消息:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\some\path\di.php:7 Stack trace: #0 C:\some\path\di.php(7): PDO->__construct('odbc:DRIVER={Mi...') #1 {main} thrown in C:\some\path\di.php on line 7

问题是:我怎样才能找到丢失的驱动程序并使其与我上面提到的代码一起工作?

PDO 支持许多不同的驱动程序,但并非所有驱动程序都默认启用。对于 Windows 上的 PDO_ODBC,我们需要确保行

extension=php_pdo_odbc.dll

在 php.ini 中启用(未注释掉)。