yii\db\Query::each PHP Méthode

each() public méthode

This method is similar to Query::batch except that in each iteration of the result, only one row of data is returned. For example, php $query = (new Query)->from('user'); foreach ($query->each() as $row) { }
public each ( integer $batchSize = 100, Connection $db = null ) : BatchQueryResult
$batchSize integer the number of records to be fetched in each batch.
$db Connection the database connection. If not set, the "db" application component will be used.
Résultat BatchQueryResult the batch query result. It implements the [[\Iterator]] interface and can be traversed to retrieve the data in batches.
    public function each($batchSize = 100, $db = null)
    {
        return Yii::createObject(['class' => BatchQueryResult::className(), 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, 'each' => true]);
    }

Usage Example

Exemple #1
0
 /**
  * Returns list of users' full names
  * @param int $limit records count
  * @return array list of users' names
  */
 public static function getUserList($limit = null)
 {
     $query = new Query();
     $query->select(['id', 'text' => "CONCAT(`u`.`first_name`,' ', `u`.`last_name`)"])->from(['u' => 'User']);
     if (isset($limit)) {
         $query->limit($limit);
     }
     $query->each();
     $command = $query->createCommand();
     return $command->queryAll();
 }
All Usage Examples Of yii\db\Query::each