php - How to access the fetched object property that is encapsulated within the SQL function count()?
Solution:
First of all try to use on fetched object. That should give you suggestions. I do believe that it is something like
$object->count
by default in most DBMS engines.
Second option (that I do really prefer in my code) is to use alias onCOUNT()
ed field:
SELECT COUNT(post_id) as tmp_value FROM posts
Then you should access it as predefined alias states:$object->tmp_value
.
In the end you should get something like this:
public function count(){
global $db;
$query = "SELECT COUNT(post_id) as tmp FROM posts";
$result = $db->select($query);
return $result[0]->tmp;
}