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!
source to share
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));
}
source to share