manuale questo sconosciuto:
$pdo->query, aka PDO::query http://php.net/manual/en/pdo.query.php ritorna un PDOStatement http://php.net/manual/en/class.pdostatement.php che implementa http://php.net/manual/en/class.traversable.php. nota su traversable:
un esempio che forse ti chiarisce meglio è quello di fare:This is an internal engine interface which cannot be implemented in PHP scripts. Either IteratorAggregate or Iterator must be used instead. When implementing an interface which extends Traversable, make sure to list IteratorAggregate or Iterator before its name in the implements clause.
Codice PHP:
$sql = 'SELECT nome FROM persone';
$result = $pdo->query($sql);
//result è PDOStatement
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
//row è un array chiave => valore, dove le chiavi sono le colonne e valore il valore della colonna per l'i-esimo record
//vedi http://php.net/manual/en/pdostatement.fetch.php per altri tipi di fetch
echo $row['nome'];
} //il ciclo finisce quando $row == null | false