使用PHP连接到Access [英] Connect to Access with PHP
本文介绍了使用PHP连接到Access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过PHP连接到Access数据库。
我已经在php.ini文件中取消注释extension = php_pdo_odbc.dll。
我把数据库放在与我尝试连接的.php文件相同的文件夹中。
我的代码到目前为止:
$ dbName =data.mdb;
if(!file_exists($ dbName)){
die(Could not find database file。
}
$ db = new PDO(odbc:DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ = $ dbName);
我的错误:
致命错误:未捕获异常'PDOException'与消息'SQLSTATE [HY000] SQLDriverConnect:-1811 [Microsoft] [ODBC Microsoft Access驱动程序]无法找到文件'(未知)'。 xampp \htdocs\Test\index.php:40堆栈跟踪:#0
C:\xampp\htdocs\Access_Test\index.php(40):PDO-> __ construct(' odbc:DRIVER = {Mi ...')#1 {main}抛出在第40行的C:\ xampp\htdocs\LAWsites\Access_Test\index.php
任何想法?
解决方案参数(
DBQ
)需要数据库文件的绝对路径:$ db = new PDO(odbc:DRIVER = {Microsoft Access Driver(* .mdb)}; DBQ =。realpath($ dbName));
I need to connect to an Access Database through PHP.
I've uncommented "extension=php_pdo_odbc.dll" in the php.ini file. I've put the database in the same folder as the .php file I'm trying to connect with.
My code so far:
$dbName = "data.mdb"; if (!file_exists($dbName)) { die("Could not find database file."); } $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName");
My error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] SQLDriverConnect: -1811 [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.' in C:\xampp\htdocs\Test\index.php:40 Stack trace: #0 C:\xampp\htdocs\Access_Test\index.php(40): PDO->__construct('odbc:DRIVER={Mi...') #1 {main} thrown in C:\xampp\htdocs\LAWsites\Access_Test\index.php on line 40
Any ideas?
解决方案The Database Location parameter (
DBQ
) requires an absolute path to your database file:$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath($dbName));
这篇关于使用PHP连接到Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文