3

I'm using CentOS 6.5 to create a PDO ODBC connection to a Microsoft Access .mdb file through PHP.

I'm using MDBTools and unixODBC.

My odbcinst.ini looks like this

[MDBToolsODBC]
Description=MDBTools Driver
Driver=/usr/lib64/libmdbodbc.so.0.0.0
FileUseage=1
Threading=1

My odbc.ini looks like this

[dashboard]
Description = Dashboard
Driver = MDBToolsODBC
Servername = localhost
Database = /mnt/inetpub/databases/dashboard.mdb
Username = 
Password = 

I am trying to connect through PHP like so

$db = new PDO("odbc:DRIVER=MDBToolsODBC;DSN=dashboard;");

After hours of getting error messages, I've finally been able to solve them all, but now when I try to connect, Google Chrome says

No data received
Unable to load the webpage because the server sent no data.
Error code: ERR_EMPTY_RESPONSE

I'm not sure if this is because of my DSN set up or not. When I do a isql dashboard I get

+----------------------------------+
| Connected!                       |
|                                  |
| sql-statement                    |
| help [tablename]                 |
| quit                             |
|                                  |
+----------------------------------+

Not sure how to go about resolving this as this is my first time using any form of linux.

Here is how I'm trying to call up the information from the database.

In files that need database information, I use

<?php
    include("inc/config.php");
?>

Commenting out the connection string

//$db = new PDO("odbc:DRIVER=MDBToolsODBC;DSN=dashboard;");

allows the HTML and CSS to load, but of course no data from the database is pulled. This is what makes me think there is an issue with the connection string of some sort.

I'm trying to perform a simple SQL query like so, which is a much more simple query than the ones I need to run and use in my development but if I can get something simple like this to work I can figure out the rest.

$problems = $db->prepare("SELECT problems.id FROM problems;");
$problems->execute();
$result = $problems->fetchColumn();
echo $result;

EDIT: I have identified that there is a 'Segmentation Fault' in the table I am trying to query. Other tables appear to be working fine!

  • 1
    Can you post the code that you're using to attempt to serve up the information? – Chad Oct 14 '14 at 20:01
  • @cwscribner I've added some additional information to the bottom of the post. The issue, I believe, does not lie with the SQL of how I am pulling the data, but the connection string itself, as explained above. Thanks. –  Oct 14 '14 at 22:23
  • Have you solved the problem? – Dimas Mar 18 '15 at 13:27

2 Answers2

0

I did a quick search for your query and found this:

http://www.wix.com/support/html5/ugc/1f678e95-c707-45c8-90ca-86a48ee98a38/2d8fe37b-cc02-4582-97da-9a93d5426a55

I think you might want to clear your browser cache/try a different browser.

The other option is to try it through the command line# php /your/script/path and see if it runs successfully that way.

Ukuser32
  • 2,147
  • 2
  • 22
  • 32
  • I've tried clearing the cache and across Chrome, Firefox and Internet Explorer. However, running a file that calls the connection string in the command line results in Error at Line: Syntax error near ( Segmentation Fault. Some of it is cut out for some reason but it's kind of helpful. –  Oct 14 '14 at 22:35
  • On inspection of another file, it shows Error at Line : syntax error near problems.start. probems.start is part of my SQL query so perhaps I was incorrect in thinking it's the connection string and is infact my SQL statement. –  Oct 14 '14 at 23:19
0

The whole point of the datasource is that you store your configuration in odbc.ini.

try{
    $db = new PDO("odbc:dashboard");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $ex){
     echo 'Connection failed: ' . $e->getMessage();
     die(var_dump($ex));
}

Should be enough , if it does not work you need to get errors, read the errors and fix, the command works, so put the username and password in odbc.ini and give it a try


Also username and password are parameters to the PDO constructor, you can try connecting by specifying everything:

try {
    $db = new PDO("odbc:dashboard", $username, $password, array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
    );
}
catch(PDOException $ex){
     echo 'Connection failed: ' . $e->getMessage();
     die(var_dump($ex));
}
meda
  • 45,103
  • 14
  • 92
  • 122
  • Should the user name and password be left as blank within odbc.ini if there is no username and password? Doing the above still results in web browsers saying Unable to load the webpage because the server sent no data. Error code: ERR_EMPTY_RESPONSE –  Oct 15 '14 at 02:37
  • Fill in the password just to be safe – meda Oct 15 '14 at 02:43
  • If I put in the incorrect DSN, the appropriate error message shows SQLSTATE[IM002]. If I put in the correct one, dashboard, no PHP error message is displayed, instead the browser error message is displayed. I am not sure how to diagnose this. –  Oct 15 '14 at 02:51
  • this sounds like it is more the browser issue than PDO since connection works – meda Oct 15 '14 at 05:44
  • I've come to think that it's a segmentation fault caused by a large table in my database. Performing queries using isql such as select * from largetable works, but when I do a help largetable in isql, I get segmentation fault. I've been able to query other tables with simple queries successfully. –  Oct 15 '14 at 05:46
  • I saw your new question how did you install odbc from source ? 80K is a lot of records to fetch have you thought about limits on recordsets ? – meda Oct 15 '14 at 06:21
  • I used yum install unixODBC. I'm not trying to retrieve all 80k results exactly, as I do have WHERE and AND clauses to limit results, it just needs to sort through them all. –  Oct 15 '14 at 06:24
  • Its not finding the driver why dont. U use freetds – meda Oct 15 '14 at 23:36