這個例子建了一個連接,用ODBC打開Access的數據庫NorthWind(安裝Access時帶的示范)。在執行了SQL語句後,返回了RecordSet對象。例子顯示了前三個字段:
<?
$dbc = new COM("ADODB.Connection");
$dbc->Provider = "MSDASQL";
$dbc->Open("nwind");
$rs = $dbc->Execute("select * from products");
$i = 0;
while (!$rs->EOF) {
$i += 1;
$fld0 = $rs->Fields(0);
$fld1 = $rs->Fields(1);
$fld2 = $rs->Fields(2);
print "$fld0->value $fld1->value $fld2->value<BR>";
$rs->MoveNext();
}
$rs->Close();
?>