Welcome Guest, Not a member yet? Register   Sign In
Bug in count_all() and count_all_results()
#1

[eluser]voidstar[/eluser]
In CI 1.7.0 both count_all() and count_all_results() use the returned value from $this->query() without first checking if it's FALSE, which can result in a fatal error.

For example if the user misspells a MySQL table name, count_all() will fail on line 332 of mysql_driver.php.

If the user misspells a field name
$this->db->where('nonexistent', 'value'); // field does not exist
$total = $this->db->count_all_results('valid_table_name');
count_all_results() will fail on line 1030 of DB_active_rec.php.

In both cases this unfortunate outcome could be easily avoided, e.g. in count_all_results()

$query = $this->query($sql);
$this->_reset_select();
if ($query == FALSE) return FALSE; // FIX


It would also be helpful if the Active Record documentation demonstrated how to get the MySQL error message in the event of a failure. For example with the fix above

$total = $this->db->count_all_results('table_name');
if ($total === FALSE)
{
$this->error_message[] = 'Count failed: ' . $this->db->_error_message();
// remainder of error reporting
}


Messages In This Thread
Bug in count_all() and count_all_results() - by El Forum - 01-11-2009, 10:17 PM
Bug in count_all() and count_all_results() - by El Forum - 01-12-2009, 10:53 AM
Bug in count_all() and count_all_results() - by El Forum - 01-12-2009, 12:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB