pdostatement::fetch-尊龙凯时官方旗舰店
$sth = $dbh->prepare("select name, colour from fruit");
$sth->execute();
/* 运用 pdostatement::fetch 风格 */
print("pdo::fetch_assoc: ");
print("return next row as an array indexed by column name\n");
$result = $sth->fetch(pdo::fetch_assoc);
print_r($result);
print("\n");
print("pdo::fetch_both: ");
print("return next row as an array indexed by both column name and number\n");
$result = $sth->fetch(pdo::fetch_both);
print_r($result);
print("\n");
print("pdo::fetch_lazy: ");
print("return next row as an anonymous object with column names as properties\n");
$result = $sth->fetch(pdo::fetch_lazy);
print_r($result);
print("\n");
print("pdo::fetch_obj: ");
print("return next row as an anonymous object with column names as properties\n");
$result = $sth->fetch(pdo::fetch_obj);
print $result->name;
print("\n");
?>
以上例程会输出:
pdo::fetch_assoc: return next row as an array indexed by column name array ( [name] => apple [colour] => red ) pdo::fetch_both: return next row as an array indexed by both column name and number array ( [name] => banana [0] => banana [colour] => yellow [1] => yellow ) pdo::fetch_lazy: return next row as an anonymous object with column names as properties pdorow object ( [name] => orange [colour] => orange ) pdo::fetch_obj: return next row as an anonymous object with column names as properties kiwi
example #2 使用一个可滚动游标获取行
#pdo #php