0

I am accessing an access database file using PHP on centos.

I am getting this error:

SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb, *.accdb)' : file not found

That's what my code looks like:

<?php
print_r(PDO::getAvailableDrivers());
$dbName = "/var/www/html/crontest/Active.accdb";
echo $dbName."<br/>";
if(!file_exists($dbName)){
        die('Error finding access database');
}
try
{
// Connection to ms access
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=".$dbName.";Uid=; Pwd=;");


$sql = "select * from Folio";
$rs = $conn->query($sql);

while($result = $rs->fetch())
{
     echo $result[0].": ".$result[1]."<br />";
}

}catch (PDOException $e) {
  echo $e->getMessage();
 }
?>

and here is the output, you can see the pdo driver is there.

Array ( [0] => mysql [1] => odbc [2] => sqlite ) /var/www/html/crontest/Active.accdb
SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open lib 'Microsoft Access Driver (*.mdb, *.accdb)' : file not found
Danyal Sandeelo
  • 11,068
  • 6
  • 37
  • 64
  • 2
    The PDO ODBC driver is there, so PDO can connect to ODBC. The ODBC MS Access driver isn't there, and is Windows-specific, so ODBC can't connect to MS Access. Get an linux-compatible driver, for .mdb files there's mdbtools, for accdb files you're generally out of luck, there are some commercial projects or you can try using a PHP-Java bridge, JDBC and UCanAccess for a very hacky but free/open source solution. – Erik A Feb 16 '21 at 14:03
  • thanks for the info @ErikA – Danyal Sandeelo Feb 17 '21 at 14:11

0 Answers0