note 27024 added to class.com
| From: | eguan1ao_at_yahoo_dot_com at rack1 dot php dot net | Date: | Wed, 20 Nov 2002 19:35:27 +0000 |
| Subject: | note 27024 added to class.com | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39765@lists.php.net to get a copy of this message | ||
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();
?>
--
http://www.php.net/manual/en/class.com.php
http://master.php.net/manage/user-notes.php?action=edit+27024
http://master.php.net/manage/user-notes.php?action=delete+27024
http://master.php.net/manage/user-notes.php?action=reject+27024