错误:找不到驱动程序-将PDO与MS Access数据库一起使用 [英] ERROR: could not find driver - Using PDO with MS Access database

查看:73
本文介绍了错误:找不到驱动程序-将PDO与MS Access数据库一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以正常使用的Microsoft Access DB.我制作了一个数据库连接类,只是一个简单的页面,其中包含该类并触发了一个简单的SQL代码.我知道代码是正确的,因为它在几周前运行良好.但是,从那时到现在,我安装了PHP,MySQL,安装了IIS并安装了PHPMyAdmin. (我们的服务器出现问题,因此尝试进入localhost,但在我完全使用PHPMyAdmin之前已解决).

I've got a fully working Microsoft Access DB. I've made a database connection class and just a simple page that includes the class and fires off a simple SQL code. I know the code is right as it was working fine a few weeks ago. However, in between then and now I installed PHP, MySQL, set up my IIS and installed PHPMyAdmin. (We were having problems with our servers so tried going localhost but it was resolved before I fully used PHPMyAdmin).

所以现在我已经将连接类和简单的php页面放到服务器上(使用FTP).但是,当我运行几个星期前使用的相同查询时,我现在收到错误消息:

So now I've got my connection class and simple php page onto the server (using FTP). However, when I run the same query I used a few weeks ago i'm now getting the error message:

ERROR:could not find driver. Warning: file_put_contents(connection.errors.txt) [function.file-put-contents]: failed to open stream: Permission denied in E:\kunden\blah\blah\blah\www\simpleTest.php on line 31

代码

connectionClass.php:

class connection{

public $con;
private $dbName;

function __construct(){
$this->dbName = $_SERVER["DOCUMENT_ROOT"] . "../database/db.mdb";
 }

function connect(){
    $this->con = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$this->dbName; Uid=Admin; Pwd=;");
    $this->con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    return $this->con;
 }   
}

simpleTest.php

if (!ini_get('display_errors')) {
ini_set('display_errors', '1');
}

try{
include_once 'classes/connectionClass.php';

//get the DB connection
$con = new connection();
$pdoConnection = $con->connect();

//query the DB
$sql = $pdoConnection->prepare("SELECT * FROM celebs");
$result = $sql->execute();
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {        
    echo $row['firstname'];
    echo $row['surname'];
 }

} catch (Exception $e){
echo 'ERROR:'.$e->getMessage();
file_put_contents('connection.errors.txt', $e->getMessage().PHP_EOL,FILE_APPEND);
}

我没有更改代码,并且想知道设置PHP,MySQL,IIS和PHPMyAdmin是否做了某些事情来阻止我的代码正常工作?我看过phpinfo();但我不确定要寻找什么.

I've not changed the code and was wondering if setting up PHP, MySQL, IIS and PHPMyAdmin has done something to prevent me from my code working? I've looked in phpinfo(); but i'm not really sure what to be looking for.

非常感谢您的帮助.

此外,在进行一些调试之后-我相当确定尝试建立新连接后,该错误围绕simpleTest.php中的代码展开.

In addition, after some de-bugging - i'm fairly certain the error revolves around the code in simpleTest.php after trying to make a new connection...

推荐答案

通过ODBC从PHP操纵Access数据库存在一些严重的局限性,这些局限性会影响PDO和较早的odbc_exec方法.如果您使用的是Windows服务器,并且绝对必须使用Access数据库后端(即

Manipulating an Access database from PHP via ODBC has some serious limitations that affect both PDO and the older odbc_exec methods. If you are using a Windows server and you absolutely must use an Access database back-end (which is strongly discouraged) I would recommend that you use ADO under com_dotnet like this:

<?php
// this code requires the following php.ini directive:
//
// extension=php_com_dotnet.dll

$con = new COM("ADODB.Connection"); 
$con->Open(
        "Provider=Microsoft.Jet.OLEDB.4.0;" .
        "Data Source=C:\\Users\\Public\\mdbTest.mdb");
$rst = new COM("ADODB.Recordset");
$rst->Open("SELECT * FROM celebs", $con, 1, 3);  // adOpenKeyset, adLockOptimistic
while (!$rst->EOF) {
    echo $rst["firstname"]->Value . " " . $rst["surname"]->Value . "<br/>";
    $rst->MoveNext;
}
$rst->Close();
$con->Close();

如果您需要完整的Unicode字符支持或希望处理二进制对象,则尤其如此.

This is especially true if you ever need full Unicode character support or expect to be manipulating binary objects.

这篇关于错误:找不到驱动程序-将PDO与MS Access数据库一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆