php - Fetching data with PDO returns duplicate results -


i have code:

... $query->setfetchmode(pdo::fetch_into, $this); $query->execute(); $data = array(); while ($row = $query->fetch()) {     $data[] = $row; } return $data; 

if put var_dump here:

var_dump($data); return $data; 

this result:

array (size=3)   0 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ...   1 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ...   2 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ... 

if put var_dump here:

while ($row = $query->fetch()) {     $data[] = $row;     var_dump($data); } 

this result:

array (size=1)   0 =>     object(chatroom)[4]         public 'id' string '1' (length=1)         ... array (size=2)   0 =>     object(chatroom)[4]         public 'id' string '2' (length=1)         ...   1 =>     object(chatroom)[4]         public 'id' string '2' (length=1)         ... array (size=3)   0 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ...   1 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ...   2 =>     object(chatroom)[4]         public 'id' string '3' (length=1)         ... 

i tried fetchall result same. doing wrong?

you trying use feature don't need.

$query->setfetchmode(pdo::fetch_into, $this); 

remove line ^


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -