Tue
29
May '07
This code demonstrates how to access a Microsoft Access Database (MDB) from PHP. Here I used PHP 5 for testing.
< ?_php
/* This example shows how to open and do operations on a Microsoft Access Database using PHP odbc functions */
$db_connection = odbc_connect(“DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=E:\root\php\DataBase.mdb”, “ADODB.Connection”, “password”, “SQL_CUR_USE_ODBC”);
echo “<hr><b>Show all tables</b><br /><br />”;
$result = odbc_tables($db_connection);
while (odbc_fetch_row($result)) {
if(odbc_result($result,“TABLE_TYPE”)==“TABLE”) {
echo “<br />” . odbc_result($result,“TABLE_NAME”);
}
}
echo “<hr /><b>SELECT code, comment from Degree</b><br /><br />”;
$res = odbc_exec($db_connection,“SELECT *FROM Degree”);
$i = 0;
while (odbc_fetch_row($res)) {
$arr = odbc_fetch_array($res,$i);
echo “<br />” . $arr[“code”] . “, “. $arr[“comment”];
$i++;
}
echo “<br /><br /><b>Number of rows = $i</b><br /><br />”;
odbc_close($db_connection);
?>

Leave a passing comment »