PHP - Jobba med databaser

Webbutveckling / PHP

Läs från Access-databas

Spar exempelkoden nedan i en fil med filändelsen .php


$db = 'C:\Inetpub\wwwroot\access_db\test1.mdb';

// Use phpinfo() to check your php.ini (odbc section) for proper ODBC user and password values 
$user = NULL;
$password = NULL;
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$db", $user, $password);

echo '<b>Connected to the Access database</b>'."\n"."\n";

//Query the database
$sql = "SELECT * FROM table1";
$result = odbc_exec($conn, $sql);

echo '<p>'."\n";
while($list = odbc_fetch_object($result)){
echo $list -> firstname.' '.$list -> lastname.'<br/>'."\n";
echo '</p>';