4

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. 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. This is a file from an external party, the web app uses 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. So far, so good, however I can't seem to query the MDB file. 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.

PDO throws the following error:

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)
9
  • have you got PDO set up to throw exceptions when problems occur? Getting an actual error message would be very helpful here. Commented Mar 25, 2020 at 11:50
  • @ADyson can you give me some pointers? Commented Mar 25, 2020 at 12:10
  • It's already in the manual! php.net/manual/en/pdo.error-handling.php Commented Mar 25, 2020 at 12:11
  • Adding try/catch to the mix still shows error > 1. Commented Mar 25, 2020 at 12:18
  • Did you add the ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); as well? Commented Mar 25, 2020 at 12:20

1 Answer 1

2

I found the solution to my problem was removing the ; from the query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.