Created
July 2, 2009 13:50
-
-
Save biakaveron/139471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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