PHP无法连接到PDO ODBC驱动程序 [英] PHP Cannot connect to PDO ODBC Driver

查看:291
本文介绍了PHP无法连接到PDO ODBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php找不到我的odbc驱动程序.我已下载并重新安装了多次.谁能帮我解决这个错误:

My php cannot find my odbc driver. I've downloaded and re-installed multiple times. Can anyone help me with this error:

QLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified"

这是我的php代码:

$dbName = "C:\Users\David\Documents\SCHOOLNEW\Assignment5-PROG1800\database\as4.mdb";
if (!file_exists($dbName))
{
    die("Could not find database file.");
}
try 
{
    // Connect
    $dbh = new PDO("odbc:Driver={Microsoft Access Driver(*.mdb, *.accdb)};Dbq=C:\Users\David\Documents\SCHOOLNEW\Assignment5-PROG1800\database\as4.mdb;Uid=Admin");

    // INSERT data
    $count = $dbh->exec("INSERT INTO part(vendorNo,description,onHand,onOrder,cost,listPrice) VALUES ('$vendorNo', '$desc', '$onHand', '$onOrder', '$cost', '$listPrice')");

    // echo the number of affected rows
    echo $count;

    // close the database connection
    $dbh = null;

}

catch(PDOException $e)
{
    echo $e->getMessage();
} 

我正在运行php with apache on xampp.所有这些都在本地计算机上.我的系统是64位.我不确定它是否与系统和驱动器类型,语法或需要安装的某些驱动程序有关.我只想将表单中的数据插入计算机上的数据库.

I'm running php with apache on xampp. This all on a local machine. My system is 64 bits. I'm not sure if it has something to do with the system and drive types or my syntax or certain drivers I need to install. I just want to insert data from my form into the database on my computer.

推荐答案

Driver={Microsoft Access Driver(*.mdb, *.accdb)}

不是有效的ODBC驱动程序名称,因为它缺少空格.较新的"ACE" ODBC驱动程序的正确名称是

is not a valid ODBC driver name because it is missing a space. The correct name for the newer "ACE" ODBC driver is

Driver={Microsoft Access Driver (*.mdb, *.accdb)}

但是,在这种情况下,PHP在32位环境中运行,并试图打开.mdb数据库,以便使用较旧的"Jet" ODBC驱动程序...

However, in this case PHP is running in the 32-bit environment and trying to open an .mdb database so the older "Jet" ODBC driver ...

Driver={Microsoft Access Driver (*.mdb)}

...也可以.

这篇关于PHP无法连接到PDO ODBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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