Skip to content

Instantly share code, notes, and snippets.

@zombor
Created June 1, 2010 13:42
Show Gist options
  • Save zombor/420951 to your computer and use it in GitHub Desktop.
Save zombor/420951 to your computer and use it in GitHub Desktop.
/**
* Same as fetch_all except you can pass a where clause
*
* @param array $where the where clause
* @param string $order_by a column to order on
* @param string $direction the direction to sort
* @param string $type the type of where to run
*
* @return Database_Result
*/
public function fetch_where($wheres = array(), $order_by = 'id', $direction = 'ASC', $type = 'and')
{
$function = $type.'_where';
$query = db::select('*')->order_by($order_by, $direction)->as_object('Model_'.inflector::singular(ucwords($this->_table_name)));
foreach ($wheres as $where)
$query->$function($where[0], $where[1], $where[2]);
return $query->execute($this->_db);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment