I am connecting the MS Access database with PHP.
My system us a server for XAMPP but the MS Access database is located in another system.
When I use the DSN system for the connection it works well but when I use the DSN-less system doesn’t work and it shows the following error:
32-bit to 64-bit error on DSN system
$conn = odbc_connect('SAP','','');
if($conn)
{
echo "";
}
else
{ echo "Failed"; }
That why I go for DSN-less system but it does not work outside the root folder.
My DSN system code
$db_username = ''; //username
$db_password = ''; //password
//path to database file
$database_path = realpath('temp.mdb');
print $database_path;
print "<br>";
$database = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$database_path; Uid=$db_username; Pwd=$db_password;");
$sql = "SELECT * FROM Product ORDER BY PCode";
$result = $database->query($sql);
while ($row = $result->fetch()) {
echo $row["PName"]."<br>";
}
Access drivers code instead of DSN-less system
DSN less Access driver code
In the code above the MS Access database works if it is located in server roor (e.g., C:/XAMPP/HTDOCS/)
I want to access the database in another drive or another computer.