Welcome Guest, Not a member yet? Register   Sign In
DB count_all_results() is not returning an int but a string
#1

[eluser]jpi[/eluser]
Hi,
It's not a bug but the userguide is saying
Code:
$this->db->like('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results();
// Produces an integer, like 17
But in fact, count_all_results (db_active_rec.php:1061) return a string that contains the number of results.

I don't know for you, but I expect any count or count_all() method to return an integer.
#2

[eluser]Phil Sturgeon[/eluser]
Good point, they could do with typecasting this with a simple return (int) $x in the funciton.

This is not really a coding fault of the EllisLab team, this is a shortfall of PHP's native MySQL binding functions. To these functions, EVERYTHING is a string, all the time. Useless!
#3

[eluser]jpi[/eluser]
Hum I am not sure...

In the file db_active_rec.php line 1074
Code:
if ($query->num_rows() == 0)
{
  return '0';
}
They explictly return a string.

And $query->num_rows() is built with php native function mysql_num_rows (in the mysql driver) which according to php doc returns an integer.
#4

[eluser]Phil Sturgeon[/eluser]
Ahh well ignore that then. Thought this was the same issue as selecting ints. Figured they would be doing select COUNT(*) which therefore gives a string. Next time I will double check ;-)




Theme © iAndrew 2016 - Forum software by © MyBB