Cake\Database\Query::bufferResults PHP Method

bufferResults() public method

When enabled the results returned by this Query will be buffered. This enables you to iterate a result set multiple times, or both cache and iterate it. When disabled it will consume less memory as fetched results are not remembered for future iterations. If called with no arguments, it will return whether or not buffering is enabled.
public bufferResults ( boolean | null $enable = null ) : boolean | $this
$enable boolean | null whether or not to enable buffering
return boolean | $this
    public function bufferResults($enable = null)
    {
        if ($enable === null) {
            return $this->_useBufferedResults;
        }
        $this->_dirty();
        $this->_useBufferedResults = (bool) $enable;
        return $this;
    }

Usage Example

Beispiel #1
2
 /**
  * Prepares a sql statement to be executed
  *
  * @param string|\Cake\Database\Query $query The query to prepare.
  * @return \Cake\Database\StatementInterface
  */
 public function prepare($query)
 {
     $this->connect();
     $options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
     $isObject = $query instanceof Query;
     if ($isObject && $query->bufferResults() === false) {
         $options = [];
     }
     $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);
     return new SqlserverStatement($statement, $this);
 }
All Usage Examples Of Cake\Database\Query::bufferResults