<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* Exercise PDOStatement::fetch styles */
print("PDO::FETCH_ASSOC: ");
print("Return next row as an array indexed by column name
");
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("
");
print("PDO::FETCH_BOTH: ");
print("Return next row as an array indexed by both column name and number
");
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
print("
");
print("PDO::FETCH_LAZY: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_LAZY);
print_r($result);
print("
");
print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as properties
");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->name;
print("
");
?>