classes/database.php
/**
	 * Fetch an array of records from the database using the SQL given.
	 *
	 * @param string $sql query to run
	 * @param array $params for the prepared statement
	 * @param mixed $as_object name to return row as (FALSE for array)
	 * @param int $cache life of result set in seconds or FALSE to disable
	 * @return array
	 */
Fetch an array of records from the database using the SQL given.
Fetch an array of records from the database using the SQL given .
public function fetch($sql, array $params = array(), $as_object = TRUE, $cache = FALSE)
	{
		if($cache AND $results = $this->_cache($sql, $params))
		{
			return $results;
		}
		$results = $this->query($sql, $params);
		if (is_string($as_object))
		{
			$results = $results->fetchAll(PDO::FETCH_ASSOC);
			foreach($results as $id => $row)
			{
				$results[$id] = new $as_object($row);
			}
		}
		elseif($as_object === TRUE)
		{
			$results = $results->fetchAll(PDO::FETCH_OBJ);
		}
		else
		{
			$results = $results->fetchAll(PDO::FETCH_ASSOC);
		}
				if($results AND $cache)
		{
			cache::set($hash, $results);
		}
		return $results;
	}
public function fetch ( $ sql , array $ params = array ( ) , $ as_object = TRUE , $ cache = FALSE ) { if ( $ cache AND $ results = $ this -> _cache ( $ sql , $ params ) ) { return $ results ; } $ results = $ this -> query ( $ sql , $ params ) ; if ( is_string ( $ as_object ) ) { $ results = $ results -> fetchAll ( PDO :: FETCH_ASSOC ) ; foreach ( $ results as $ id => $ row ) { $ results [ $ id ] = new $ as_object ( $ row ) ; } } elseif ( $ as_object === TRUE ) { $ results = $ results -> fetchAll ( PDO :: FETCH_OBJ ) ; } else { $ results = $ results -> fetchAll ( PDO :: FETCH_ASSOC ) ; } if ( $ results AND $ cache ) { cache :: set ( $ hash , $ results ) ; } return $ results ; }
Fetch an array of records from the database using the SQL given.
Fetch an array of records from the database using the SQL given .
// Try to get the cached results first // Run the query // If we should fetch the results into an object // Should we cache the results?
