0
  • 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.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
lonecoder
  • 11
  • 4
  • I don't have access to php.ini – lonecoder May 29 '20 at 11:27
  • "file not found" means the file isn't in the location you specified. Obviously we cannot see the actual file path you specified, and nor can we see the contents of your hosting account's file storage. So it's a little tricky to suggest what precisely to do about it, other than to say "you need to put the file in the right place, and specify the right path to it". To improve security, avoid putting the Access file in a folder where it would be possible for someone to download it directly via a URL. – ADyson May 29 '20 at 11:39
  • As a wider point though, Access is an unsuitable backend for a web application. Consider switching to an alternative such as MySQL, SQL Server Express, or even SQLite. – ADyson May 29 '20 at 11:42
  • @ADyson Thanks for your reply..By 'file not found ', it is not the access file which can not be found, but the driver manager for ms access (.accdb) although I checked the PHP configuration by and made sure that the pdo, pdo_mysql , and mysql extensions are enabled. – lonecoder May 31 '20 at 14:49
  • $dbName = "attacher.accdb"; echo $dbName; if (!file_exists($dbName)) { die("Could not find database file."); } else { try { echo ("
    Database is : "attacher.accdb
    " ; $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$dbName; Uid=admin; Pwd=;"); // $db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); echo 'connected';}
    – lonecoder May 31 '20 at 14:58
  • _"although I checked the PHP configuration by and made sure that the pdo, pdo_mysql , and mysql extensions are enabled"_ ... why would the mysql drivers be important here? You need Access drivers. – ADyson Jun 02 '20 at 22:17
  • Is your free website running Linux or Windows? If it's Linux, the native Access driver (which ODBC relies on) may not be installed. You'd have to contact the site's support to see if they support it. P.S. As a wider point, MS Access is not a good choice for the back-end of a web application. Consider moving your data to MySQL or something similar, which will work better overall. – ADyson Jun 02 '20 at 22:28

0 Answers0