I’m getting a Call to a member function fetchColumn() on a non-object error when I’m executing my query with a mysql prepared statement on PHP
$result= $dbh->prepare("SELECT COUNT(*) FROM table WHERE id_1 = ? AND id_2 = ?");
$result->execute(array($id_1,$id_2))->fetchColumn();
echo count($result);
What is the reason for this error? Am I writing the statement incorrectly?
Thanks
PDOStatement::execute returns a boolean to check whether your query has executed properly. You can only chain method calls if each methods returns the reference of your
PDOStatementobject. You want to do this