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!
I did a quick search for your query and found this:
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.
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));
}