pdostatement::fetch-尊龙凯时平台在线地址
function readdataforwards($dbh) {
$sql = 'select hand, won, bet from mynumbers order by bet';
$stmt = $dbh->prepare($sql, array(pdo::attr_cursor => pdo::cursor_scroll));
$stmt->execute();
while ($row = $stmt->fetch(pdo::fetch_num, pdo::fetch_ori_next)) {
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
print $data;
}
}
function readdatabackwards($dbh) {
$sql = 'select hand, won, bet from mynumbers order by bet';
$stmt = $dbh->prepare($sql, array(pdo::attr_cursor => pdo::cursor_scroll));
$stmt->execute();
$row = $stmt->fetch(pdo::fetch_num, pdo::fetch_ori_last);
do {
$data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";
print $data;
} while ($row = $stmt->fetch(pdo::fetch_num, pdo::fetch_ori_prior));
}
print "reading forwards:\n";
readdataforwards($conn);
print "reading backwards:\n";
readdatabackwards($conn);
?>
以上例程会输出:
reading forwards: 21 10 5 16 0 5 19 20 10 reading backwards: 19 20 10 16 0 5 21 10 5
example #3 构造顺序
#pdo #php