PHP 8.5.0 Beta 1 available for testing

Voting

: min(seven, eight)?
(Example: nine)

The Note You're Voting On

eguan1ao_at_yahoo_dot_com
22 years ago
An example of connecting to a Microsoft Access database, executing an SQL query, and displaying the results in HTML.

<?php

$db
= 'C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb';

$conn = new COM('ADODB.Connection');

// Two ways to connect. Choose one.
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
//$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");

$sql = 'SELECT ProductName, QuantityPerUnit, UnitPrice
FROM Products
ORDER BY ProductName'
;
$rs = $conn->Execute($sql);

?>

<table>
<tr>
<th>Product Name</th>
<th>Quantity Per Unit</th>
<th>Unit Price</th>
</tr>
<?php while (!$rs->EOF): ?>
<tr>
<td><?= $rs->Fields['ProductName']->Value ?></td>
<td><?= $rs->Fields['QuantityPerUnit']->Value ?></td>
<td><?= $rs->Fields['UnitPrice']->Value ?></td>
</tr>
<?php $rs->MoveNext() ?>
<?php
endwhile ?>
</table>

<?php

$rs
->Close();
$conn->Close();

?>

<< Back to user notes page

To Top