SELECT COUNT(*) AS count – How to use this count

It’s not recommended to use reserved words for names in SQL. So I call the count result cnt instead. As your function is scalar, i.e. you expect only one value back, you can use:

$count = $mysqli->query("select count(*) as cnt from cars")->fetch_object()->cnt; 

Leave a Comment