I'm trying to implement PDO in my web site and i was checking the use of fetch and fetchAll and found this strange behaviour. This code works perfectly:
$query="SELECT `id`, `username`, `nome`, `email`, `pwd`, `level` FROM `users` WHERE `username`= ? LIMIT 1";
$stmt=$myconn->prepare($query);
$stmt->bindParam(1, $uname);
$stmt->execute();
$row=$stmt->fetchAll();
print_r($row);
while this one doesn't work: fetch returns false with no error code (00000):
$query="SELECT `id`, `username`, `nome`, `email`, `pwd`, `level` FROM `users` WHERE `username`= ? LIMIT 1";
$stmt=$myconn->prepare($query);
$stmt->bindParam(1, $uname);
$stmt->execute();
while($row = $stmt->fetch()) {
echo $row->username . "\n";
echo $row->nome . "\n";
echo $row->email . "\n";
}
Any idea why?