我正在尝试为我的访问数据库连接创建一个类并返回一个记录集,然后使用 MoveNext() 遍历 RS。
class AccessDBConnection
{
private $db;
private $sql;
function __construct($db, $sql) {
$conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");
$rs = $conn->Execute($sql);
return $rs;
}
采用:
function testclass () {
$rs = new AccessDBConnection("e:\database.mdb", "SELECT StudentID, UserName FROM MyTable WHERE StudentID = 'BJxxxx'");
while (!$rs->EOF) {
$SID = $rs->Fields['StudentID']->Value;
$UN = $rs->Fields['UserName']->Value;
echo $SID . " -- CLASS TEST -- " . $UN . "<br>";
$rs->MoveNext();
}
}