PHP连接到访问数据库(.mdb) [英] PHP connecting to access database (.mdb)

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

问题描述

我目前正在努力获取一个PHP脚本以连接到MS Access数据库2007,以便该PHP脚本可以从中检索信息.

I am currently working getting a PHP script to connect to a MS access database 2007, so that the PHP script can retrrive information from it.

有人知道实现此目标的任何方法吗,我相信创建ODBC连接可能是前进的方法,但是对此事的任何指导,我将不胜感激.

Does anyone know any way of accomplishing this I do believe that creating an ODBC Connection may be the way forward but I would appreciate any guidance towards this matter.

非常感谢任何人愿意给我的帮助

Many thanks for any help anyone is willing to give me

詹姆斯

推荐答案

通常,您会执行以下操作:

Normally, you'd do something like this:

$dbName = $_SERVER["DOCUMENT_ROOT"] . "products\products.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");

成功的连接将允许从PHP执行SQL命令以读取或写入数据库.但是,如果收到错误消息"PDOException无法找到驱动程序",则可能是未安装PDO ODBC驱动程序.使用phpinfo()函数检查您的安装中是否有对PDO的引用.

A successful connection will allow SQL commands to be executed from PHP to read or write the database. If, however, you get the error message "PDOException Could not find driver" then it’s likely that the PDO ODBC driver is not installed. Use the phpinfo() function to check your installation for references to PDO.

如果不存在PDO ODBC的条目,则需要确保您的安装包括PDO扩展名和ODBC驱动程序.为此,请在Windows上取消注释php.ini中的行extension=php_pdo_odbc.dll,重新启动Apache,然后尝试再次连接到数据库.

If an entry for PDO ODBC is not present, you will need to ensure your installation includes the PDO extension and ODBC drivers. To do so on Windows, uncomment the line extension=php_pdo_odbc.dll in php.ini, restart Apache, and then try to connect to the database again.

在您的情况下,如果.mdb文件位于外部服务器上,我相信它会起作用,但是您必须能够从服务页面的位置对其进行点击.

In your case I believe it would work if the .mdb file is on an external server, but you'd have to be able to hit it from where you're serving the page.

不确定这是内部网还是跨公共互联网,但是如果是公共互联网,则可能需要重做一些工作流程,因为通常不需要以这种方式访问​​数据库.

Not sure if this is intranet or across the public internet, but if it's public internet you might want to rework your work flow a bit, as generally making your database accessible that way is not something you'd want to do.

来源:将访问数据库与PHP一起使用

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

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