: Call to a member function rowCount() on a non-object in C:\wamp\www\prjy\classes\user.php on line 34
Line 29-32
$this->sth = $this->dbh->prepare("SELECT id, userlevel FROM users WHERE username = ? AND password = ?");
$this->sth->bindParam(1, $username);
$this->sth->bindParam(2, $password);
$this->data = $this->sth->execute();
Line 34
if ($this->data->rowCount() > 0)
I want to save the result object in another variable, so I can execute another query and depending on the result, I return what is correct… Can’t I save the result, (execute()) in a variable like above? How do I solve it else way?
PDOStatement::rowCount()returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.For most databases,
PDOStatement::rowCount()does not return the number of rows affectedby a
SELECTstatement. Instead,use
PDO::query()to issue aSELECT COUNT(*)statement with the same predicates as your intended SELECT statement,then use
PDOStatement::fetchColumn()to retrieve the number of rows that will be returned.Reference