Reputation: 5074
I'm trying the native query in doctrine (the real native).
public function recupererNoms()
{
$sql = 'SELECT id, nom FROM table;';
$stmt = $this->getEntityManager()->getConnection()->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
This query returns:
array(4) { ["id"]=> string(1) "1" [0]=> string(1) "1" ["nom"]=> string(4) "toto" [1]=> string(4) "toto" }
Information is somehow duplicated in this returned table. for instance, in my sql request I specified the name and I got ["nom"]=> string(4) "toto" [1]=> string(4) "toto"
. How do I get rid of [1]=> string(4) "toto"
and ["id"]=> string(1) "1" [0]=> string(1) "1"
?
Upvotes: 0
Views: 1089
Reputation: 1908
Try
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
For other options have a look at PDOStatement::fetch
Upvotes: 2