PHP:调试与Access数据库(.accdb)的PDO连接 [英] PHP: Debugging PDO connection to Access database (.accdb)

查看:327
本文介绍了PHP:调试与Access数据库(.accdb)的PDO连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,想使用PDO类连接到ms-access(accdb)数据库. 环境:PHP(5.5.11)/XAMPP/Windows 7 pro.启用了用于ODBC(win32)的PDO驱动程序.

class db{
  protected $dbName = "C:\xampp\htdocs\BillboardsManagement\Core\config\Billboards.accdb";
  protected $Uid="";
  protected $Upass="";
  protected $conn;

  public function __construct() {
    try{
        $this -> conn = new PDO('odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=$this->$dbName;Uid=$this->$Uid;Pwd=$this->$Upass');
    } catch (Exception $e) {
        echo "\n $e-> getMessage()\n";   
    }
  }
}

当我尝试实例化该类时,出现以下错误:

消息为"SQLSTATE [IM002]"的

例外"PDOException" SQLDriverConnect:0 [Microsoft] [ODBC驱动程序管理器]数据源名称 找不到,并且未指定默认驱动程序 C:\ xampp \ htdocs \ BillboardsManagement \ Core \ config \ config.php:13堆栈 跟踪:#0 C:\ xampp \ htdocs \ BillboardsManagement \ Core \ config \ config.php(13): PDO-> __ construct('odbc:DRIVER = {Mi ...')#1 C:\ xampp \ htdocs \ BillboardsManagement \ Views \ selectBB.php(3): db-> __ construct()#2 {main}-> getMessage()致命错误:调用 成员函数对非对象中的对象的prepare() C:\ xampp \ htdocs \ BillboardsManagement \ Core \ classes \ bbClasses.php在 第11行

预先感谢您的帮助.

更新:我了解之前也回答过类似的问题.但是我正在学习中.上一篇文章的答案是使用adodb而不是PDO(出于我完全同意的原因),但是我仍然对在我的特定情况下出了什么问题感到好奇.我仍然无法确定我的代码是错误的还是odbc驱动程序或配置问题.

解决方案

大量阅读后,我发现我使用的

When I try to instantiate the class, I get the following error:

exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' in C:\xampp\htdocs\BillboardsManagement\Core\config\config.php:13 Stack trace: #0 C:\xampp\htdocs\BillboardsManagement\Core\config\config.php(13): PDO->__construct('odbc:DRIVER={Mi...') #1 C:\xampp\htdocs\BillboardsManagement\Views\selectBB.php(3): db->__construct() #2 {main}-> getMessage() Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\BillboardsManagement\Core\classes\bbClasses.php on line 11

Thanks in advance for your help.

Updates: I understand that a similar question was answered before. But I am in a learning process. The answer to the previous post was to use adodb instead of PDO ( for reasons I totally agree with) , but I am still curious about what went wrong in my particular situation. I still cannot determine whether my code was faulty or it was some odbc driver or configuration issue.

解决方案

After lots and lots of reading, I discovered I was using the wrong version of the Microsoft Access Database Engine: The 64-bit version doesn't have the 32-bit driver for *.accdb format.

Thanks again for your enlightening support.

这篇关于PHP:调试与Access数据库(.accdb)的PDO连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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