Last active
October 3, 2017 10:28
-
-
Save dertajora/47d492243b8ec1ad8e4cfbad29719776 to your computer and use it in GitHub Desktop.
How to query to MS DB Access using PHP. #This script is used to do query in MS DB Access in PHP. I use it on little project when I'm working as Web Developer in Garena to build an automation system for specific task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#October 3, 2017 | |
#First activate pdo_odbc in your server | |
#extension=php_pdo_odbc.dll | |
#then | |
#odbc.defaultbinmode=1 | |
#odbc.defaultlrl=4096 | |
#odbc.max_links=-1 | |
#odbc.max_persistent=-1 | |
#odbc.check_persistent=On | |
#odbc.allow_persistent=On | |
#credential | |
$db_username = ''; //username | |
$db_password = ''; //password | |
//path to database file | |
$database_path = 'D:\xampp\htdocs\absen_folder\Pga.mdb'; | |
//check file exist before we proceed | |
if (!file_exists($database_path)) { | |
die("Access database file not found !"); | |
} | |
//create a new PDO object | |
$database = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$database_path; Uid=$db_username; Pwd=$db_password;"); | |
// simple query | |
$sql = "SELECT * FROM Process where ID = '00040531'"; | |
$result = $database->query($sql); | |
while ($row = $result->fetch()) { | |
echo (string)$row["ID"]." ".$row["Name"]; | |
echo "<br>"; | |
} | |
// join query | |
// can't use JOIN, you should use INNER JOIN | |
$sql = "SELECT e.Name, e.ID, p.StartTime, p.EndTime, ClassWS, ClassWE FROM Process p INNER JOIN Employee e on e.ID = p.ID where e.ID = '00040531'"; | |
$result = $database->query($sql); | |
echo "<Table border =1>"; | |
while ($row = $result->fetch()) { | |
echo (string)$row["ID"]." ".$row["Name"]." ".$row["StartTime"]." ".$row["EndTime"]." ".$row["ClassWS"]; | |
echo "<tr><td>".(string)$row["ID"]."</td><td> ".$row["Name"]."</td><td> ".$row["StartTime"]."</td><td> ".$row["EndTime"]."</td><td> ".$row["ClassWS"]."</td></tr>"; | |
echo "<br>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment