クエリの結果を 2 回使用したいと考えています。
ポインターの位置を変更して、結果をもう一度最初から読み取り始めるにはどうすればよいですか?
以下の例 (簡単にするために画面に出力するだけです):
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";
}