CodeIgniter Forums
Count_ALL error table and num_rows. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Count_ALL error table and num_rows. (/showthread.php?tid=47002)



Count_ALL error table and num_rows. - El Forum - 11-22-2011

[eluser]Unknown[/eluser]
This is necessary?

Original Code:
Code:
/**
  * "Count All" query
  *
  * Generates a platform-specific query string that counts all records in
  * the specified database
  *
  * @access public
  * @param string
  * @return string
  */
function count_all($table = '')
{
  if ($table == '')
  {
   return 0;
  }

  $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));

  if ($query->num_rows() == 0)
  {
   return 0;
  }

  $row = $query->row();
  return (int) $row->numrows;
}

Change code:

Code:
/**
  * "Count All" query
  *
  * Generates a platform-specific query string that counts all records in
  * the specified database
  *
  * @access public
  * @param string
  * @return string
  */
function count_all($table = '')
{
  if ($table == '')
  {
   return 0;
  }

  $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
  
  if(count($this->_error_message()) == 0){
   if ($query->num_rows() == 0)
   {
    return 0;
   }
  
   $row = $query->row();
   return (int) $row->numrows;
  }
}