For example, let\'s use some simple data set
+---------+------+------+------------+
| name | age | sex | position |
+---------+------+------+---------
This answer is out of date, please see this other answer instead.
It looks like there's no way to do this as part of fetchAll.
Your best bet is going to be creating a class that extends PDO, adding a utility method to it.
public function queryKeyedAssoc($query, $params, $key) {
$sth = $this->prepare($query);
$sth->execute($params);
$res = array();
while($row = $sth->fetch(PDO::FETCH_ASSOC))
$res[ $row[$key] ] = $row;
return $res;
}