我在Windows 7 ampps上安装了PHP 5.5。我正在尝试使用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++;
}
但是,我收到以下错误消息:
致命错误:未捕获的异常'PDOException',消息'不能 在C:\ some \ path \ di.php中查找驱动程序:7堆栈跟踪:#0 C:\ some \ path \ di.php(7):PDO-&gt; __ construct('odbc:DRIVER = {Mi ...')#1 {main}在第7行的C:\ some \ path \ di.php中抛出
问题是:我怎样才能找到错过的驱动程序并使其与我上面提到的代码一起使用?
答案 0 :(得分:1)
PDO支持许多不同的驱动程序,但默认情况下并非所有驱动程序都启用。对于Windows上的PDO_ODBC,我们需要确保该行
extension=php_pdo_odbc.dll
在php.ini中启用(未注释掉)。