无法通过PHP连接到Access数据库 [英] Can't connect through PHP to an Access Database

查看:236
本文介绍了无法通过PHP连接到Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须通过PHP建立与Access数据库的连接,但是每次尝试都会出现此错误:

致命错误:未捕获的异常'com_exception'

有消息:

'源: Microsoft OLE DB
服务组件
描述:初始格式的数据格式 den OLE DB-Angaben."在E:\ path \ to \ phpfile.php:93
堆栈跟踪:#0 E:\ path \ to \ phpfile.php(93):com-> Open('DRIVER = {Microso ...')#1 {main}进入

德语文本的含义类似于初始化字符串的格式在OLE DB语句中并不常见.

我的连接代码如下

$db = 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\") & ("\\db\\db.mdb") & ";"';
$conn = new COM("ADODB.Connection"); 
$conn->Open($db);

我不知道怎么了.在纯ASP中,它可以正常工作,但在PHP中则不能.

预先感谢

解决方案

使用PDO代替使用"ADODB.Connection"模块,因为它是目前的最佳选择,也是一种最佳实践,这里是文档: http://php.net/manual/zh/book.pdo.php

但是,如果不适合使用PDO,则可以看到ODBC(推荐使用PDO),这是一个本机PHP模块.这里是文档: http://php.net/manual/zh/book.uodbc. php
要开始连接,请执行以下操作:$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

I have to establish a connection via PHP to a Access Database, but everytime I try I get this error:

Fatal error: Uncaught exception 'com_exception'

With message:

'Source: Microsoft OLE DB
Service Components
Description: Das Format der Initialisierungszeichenfolge entspricht nicht den OLE DB-Angaben.' in E:\path\to\phpfile.php:93
Stack trace: #0 E:\path\to\phpfile.php(93): com->Open('DRIVER={Microso...') #1 {main} thrown in

The German text means something like "the format of the initialization string is not common of the OLE DB statements.

My connection code looks like

$db = 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\") & ("\\db\\db.mdb") & ";"';
$conn = new COM("ADODB.Connection"); 
$conn->Open($db);

I can't figure out what's wrong. In pure ASP it works fine, but not in PHP.

Thanks in advance

解决方案

Instead of using the "ADODB.Connection" module use PDO since it's currently the best option out there and is a best practice, Here is the documentation: http://php.net/manual/en/book.pdo.php

But if PDO isn't for you then see ODBC (PDO RECOMMENDED) which is a native PHP module. Here is the documentation: http://php.net/manual/en/book.uodbc.php
To start a connection you would do this: $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

这篇关于无法通过PHP连接到Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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