Query an MS Access Database with PHP

Below is a PHP script to connect to an MS Access database using ODBC DSN.

 


<html>
<head><title>PHP Access TEST</title></head>
<body>
<h2>Access Database / DSN Test</h2>
<table border="1">

<?php
$DSN="myODBC_DSN";
$DSN_User="";
$DSN_Passwd="";
$QueryString="SELECT id, FirstName, LastName, Email FROM tblContact";

$Connect = odbc_connect( $DSN, $DSN_User, $DSN_Passwd );
$Result = odbc_exec( $Connect, $QueryString );

echo "\t" . "<tr>\n";
echo "\t\t" . "<td>id</td><td>FirstName</td><td>LastName></td><td>Email</td>" . "\n";

while( odbc_fetch_row( $Result ) )
{
$id = odbc_result($Result,"id");
$FirstName = odbc_result($Result,"FirstName");
$LastName = odbc_result($Result,"LastName");
$Email = odbc_result($Result,"Email");

echo "\t" . "<tr>\n";
echo "\t\t" . "<td>" . $id . "</td><td>" . $FirstName . "</td><td>" . $LastName . "</td><td>" . $Email . "</td>\n";
echo "\t" . "</tr>\n";
}

odbc_free_result( $Result );
odbc_close( $Connect );
?>
</table>
</body>
</html>
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SQL server- network related or instance-specific error happened while connection establishing

  Instance-specific or network related error happening while connecting to SQL server   Please...

OleDB connection string examples

OleDB connection string examples MS Access (Jet) "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA...

Do you allow custom COM components?

Do you allow custom COM components? We are not offering to install the custom COM components...

Error when accessing a WCF services

Error when accessing a WCF services Error when accessing a WCF service: "IIS specified...

How to cache static contents to client with UseMaxAge?

You can consider to caches static contents to the client with UseMaxAge if your website has too...