Stwosch Stwosch - 22 days ago 8
PHP Question

PHP PDO Trying to get property of non-object

I'm getting

Notice: Trying to get property of non-object in
when I'm trying to

foreach ($query->fetch(PDO::FETCH_OBJ) as $row) {
echo $row->id_users;
echo $row->username;
echo $row->password;
echo $row->email;
}


When I use
print_r($query->fetch(PDO::FETCH_OBJ))
i'm getting

Class Object ( [id_users] => 1 [username] => test [password] => test [email] => test )

Answer

Typically to iterate througha recordset you would do something along these lines.

while( $row = $query->fetch(PDO::FETCH_OBJ) ){
        echo $row->id_users;
        echo $row->username;
        echo $row->password;
        echo $row->email;
}