PDO: How to access Microsoft Access file on Linux?

I'll-Be-Back picture I'll-Be-Back · Nov 20, 2012 · Viewed 18.4k times · Source

I have managed to read data of Microsoft Access file (.accdb) on Windows using PDO but I'm having problem getting to work on Linux (CentOS). I can see modules is installed:

[root@rapid host]# php -m | grep PDO
PDO
PDO_ODBC
[root@rapid host]# php -m | grep odbc
odbc

code:

<?php
    try{
        $dbhAccess = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=/root/access/data.accdb;Uid=Admin");
    }
    catch(PDOException $e){
        echo $e->getMessage();
        exit();
    }

I get an erro when I execute (CLI) PHP file:

[root@rapid host]# php access.php
SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified

Answer

CapelliC picture CapelliC · Nov 20, 2012

you should install the MDB driver.

I have no way to try it now, but I think that MDB Tools (specifically the ODBC driver) can do what you' re interested to.