I can't understand this error, could someone please explain it to me?
PHP Fatal error: Call to a member function fetchColumn() on a non-object in /user/dal.php on line 27
I am trying to get the count of the last query, by using regex to perform a new SELECT COUNT(*)
query on the last query. The problem is $stmt->fetchColumn()
causes a fatal error and then I get Error 500
.
function dbRowsCount($sql) {
global $db;
$regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
if (preg_match($regex, $sql, $output) > 0) {
$stmt = $db->query("SELECT COUNT(*) FROM {$output[1]}", PDO::FETCH_NUM);
return $stmt->fetchColumn();
}
return false;
}
What am I doing wrong?