Skip to content

Instantly share code, notes, and snippets.

@biakaveron
Created July 2, 2009 13:50
Show Gist options
  • Save biakaveron/139471 to your computer and use it in GitHub Desktop.
Save biakaveron/139471 to your computer and use it in GitHub Desktop.
/**
* Count records for a given table
*
* @param string table name
* @param array WHERE conditions
* @return int
*/
public function count_records($table = FALSE, $where = NULL)
{
$this->_select = array(array('COUNT("*")', 'records_found'));
if (count($this->_from) < 1)
{
if ($table === FALSE)
throw new Database_Exception('Database count_records requires a table');
$this->from($table);
}
if ($where !== NULL)
{
$this->where($where);
}
$result = $this->execute()->current();
return $result['records_found'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment