在Windows版的PHP中使用ADO
2001-02-24 11:45:45 来源:WEB开发网核心提示:这个例子建了一个连接,用ODBC打开access的数据库NorthWind(安装Access时带的示范),在Windows版的PHP中使用ADO,在执行了SQL语句后,返回了RecordSet对象
这个例子建了一个连接,用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();
?>
<?
$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();
?>
更多精彩
赞助商链接