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

Description=MDBTools Driver


My odbc.ini looks like this

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.


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



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;");
$result = $problems->fetchColumn();
echo $result;


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


source to share

2 answers

The whole point of a data source is that you store your configuration in odbc.ini


    $db = new PDO("odbc:dashboard");
catch(PDOException $ex){
     echo 'Connection failed: ' . $e->getMessage();


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(
catch(PDOException $ex){
     echo 'Connection failed: ' . $e->getMessage();




I did a quick search and found this:


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.



All Articles