db\Query batch()

batch() public method

Starts a batch query.

A batch query supports fetching data in batches, which can keep the memory usage under a limit. This method will return a yii\db\BatchQueryResult object which implements the Iterator interface and can be traversed to retrieve the data in batches.

For example,

$query = (new Query)->from('user');
foreach ($query->batch() as $rows) {
    // $rows is an array of 100 or fewer rows from user table
}
public yii\db\BatchQueryResult batch ( $batchSize = 100, $db = null )
$batchSize integer

The number of records to be fetched in each batch.

$db yii\db\Connection

The database connection. If not set, the "db" application component will be used.

return yii\db\BatchQueryResult

The batch query result. It implements the Iterator interface and can be traversed to retrieve the data in batches.

doc_Yii
2016-10-30 16:58:57
Comments
Leave a Comment

Please login to continue.