我想使用兩次查詢的結果。
如何重新定位指針以開始第二次開始讀取結果?
實例下(只是打印篩選簡單):如何重新讀取perl數據庫查詢結果
if ($dbh = DBI->connect("DBI:mysql:database=tng;host=ip", "username", "password")) {
$strSQL = "select * from table";
if ($strQuery = $dbh->prepare($strSQL)) {
if ($strQuery->execute()) {
while (@data = $strQuery->fetchrow_array()) {
print $data[0];
}
--reposition to top and reread the query result and do something else with the data-- $strQuery->finish;
}
else {
$strMsg = "$strDateTime ERROR -- unable to execute statement: " . $strQuery->errstr . "\n";
print logFile "$strMsg";
}
}
else {
$strMsg = "$strDateTime ERROR -- unable to prepare statement: " . $dbh->errstr . "\n";
print logFile "$strMsg";
}
$dbh->disconnect();
}
else {
print logFile "$strDateTime ERROR -- unable to connect to iptables database ... " . DBI->errstr . " \n";
}
謝謝一堆:) – 2012-04-18 04:31:59
當處理巨大的文件時,循環方法通常優先於一次sl the文件。同樣適用於大型數據集。所以問題是恕我直言,沒有必要。 – dgw 2012-04-18 08:02:20
@dgw,獲得OP所需的功能,DBI將不得不將整個結果集自動揣入內存!你實際上同意我的觀點。 – ikegami 2012-04-18 09:41:37