I am writing my PHP blog engine. I am using PDO for it. And now, when I am writing class Member – I have an error.
Fatal error: Call to a member function fetch() on a non-object in
/home/tucnak/Server/scripts/php/classes/Member.php on line 42
And source code of my Class:
public function authMember($user, $password)
{
$password = hashIt($password);
$count = 100500;
$count = $this->db->query("SELECT count(*) FROM users-general WHERE nick = $user AND password = $password;")->fetch();
echo($count);
// if ($count == 1){ return 1; } else { throw new Exception("",491); }
}
I have an error using this function.
Your query probably fails because you don’t have quotes wrapped around your query.
When that happens,
query()will returnfalseinstead of an object, breaking the chain.Don’t do it this way; run the query first, save its result, then check whether it’s false.
By the way, you should really use prepared statements – your current statement is vulnerable to SQL injection.