ODBC PDO returns "No data"

I am using CentOS 6.5 to create PDO ODBC connection to Microsoft Access.mdb file via PHP.

I am 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 via PHP like so

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

      

After hours of receiving error messages, I was finally able to resolve them, 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 it has something to do with my DSN configured or not. When I do isql dashboard

I get

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

      

Not sure how to solve this as this is my first time using any form of Linux.

This is how I am trying to fetch information from the database.

On files that need information about the database, I use

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

      

Commenting out the connection string

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

      

allows HTML and CSS to be loaded, but of course no data is pulled from the database. This is what makes me think there is a problem with the connection string.

I'm trying to execute a simple SQL query similar to this, which is a much simpler query than the ones I need to run and use in my development, but if I can do something simple to get it working, I can figure out the rest.

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

      

EDIT: I found that the table I am trying to query has a "Segmentation Fault". Other tables look great!

+3


source to share


2 answers


The whole point of a data source 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 doesn't work, you need to get errors, read errors and fix, the command works, so put your username and password in odbc.ini

and try




Also username and password are parameters of PDO constructor, you can try to connect 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));
}

      

+1


source


I did a quick search and found this:

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



I think you might need to clear your browser cache / try another browser.

Another option is to try it through command line # php / your / script / path and see if it succeeds that way.

0


source







All Articles