Why I can't connect to an msaccess database (.accdb) with php code on a free website

203 views Asked by At
  • I checked the pdo_odbc extension by <?php phpinfo(); ?> and found it enabled.
  • I resolved the file path by $_SERVER["DOCUMENT_ROOT"] and echoed the result, then I used the following code to connect:
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$dbName; Uid=; Pwd=;");

The error I get is:

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

  • I don't have access to php.ini to edit it.

This is my code:

$dbName = "filename.accdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
else
{
  try{
   echo 'Connecting ... ';
   echo $dbName ."</br>";
   $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$dbName; Uid=; Pwd=;");
    $sql  = "SELECT * FROM Tblperson";
    $sql .= " WHERE id = 1"; 
    echo $sql;
    $result = $db->query($sql);
    $row = $result->fetch();
    //......

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

I can smoothly use the above code with WAMP on Windows 10 64-bit, but on free website ( and even on a paid one) i get the same error shown in my original question although I make sure all required PHP extensions are enabled.

0

There are 0 answers