简体   繁体   English

在 Linux 上从 PHP 连接到 MS Access 数据库

[英]Connecting to a MS Access database from PHP on Linux

My client has been running a Windows server for years but we are now moving to a separate Linux machine for the web app I have created for them.我的客户多年来一直在运行 Windows 服务器,但我们现在正在为我为他们创建的 Web 应用程序迁移到一台单独的 Linux 机器。 Currently we run PHP on the Windows server on which we are able to connect to an MDB file that is on the same disk.目前,我们在 Windows 服务器上运行 PHP,我们可以在该服务器上连接到同一磁盘上的 MDB 文件。 This is a file from an external party, the web app uses MySQL.这是来自外部方的文件,Web 应用程序使用 MySQL。 In the new setup we have a Linux web server (Apache/MySQL/PHP) and a Windows 2016 server which are connected via VPN and we have mounted a share on the Windows server in which the MDB file is located.在新设置中,我们有一个 Linux Web 服务器 (Apache/MySQL/PHP) 和一个 Windows 2016 服务器,它们通过 VPN 连接,并且我们在 MDB 文件所在的 Windows 服务器上安装了一个共享。 So far, so good, however I can't seem to query the MDB file.到目前为止,一切都很好,但是我似乎无法查询 MDB 文件。 The connection is made, not error there, but every query I run returns an error or nothing not sure.连接已建立,没有错误,但我运行的每个查询都会返回错误或不确定。 This is my code:这是我的代码:

<?php
$db=new PDO("odbc:Driver=MDBTools; DBQ=/mnt/<dir>/<file>.mdb;");
$query=$db->query("SELECT * FROM <table>;");

$return=array();
if($query) {
     while($result=$query->fetch(PDO::FETCH_ASSOC)) {
         $return[]=$result;
     }
}else $return['error']=1;

//close
$query=null;
$db=null;

print_r($return);
?>

Currently everything returns error > 1.目前一切都返回错误> 1。

PDO throws the following error: PDO 抛出以下错误:

Connection failed: SQLSTATE[08001]: Client unable to establish connection: 1 Couldn't parse SQL (SQLExecute[1] at /build/php7.2-pRoOsC/php7.2-7.2.24/ext/pdo_odbc/odbc_stmt.c:260)

I found the solution to my problem was removing the ;我发现我的问题的解决方案是删除 ; from the query.从查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM