Doctrine\DBAL\Query\QueryBuilder::setFirstResult PHP Method

setFirstResult() public method

Sets the position of the first result to retrieve (the "offset").
public setFirstResult ( integer $firstResult )
$firstResult integer The first result to return.
    public function setFirstResult($firstResult)
    {
        $this->state = self::STATE_DIRTY;
        $this->firstResult = $firstResult;
        return $this;
    }

Usage Example

Ejemplo n.º 1
42
 /**
  * @param QueryBuilder $queryBuilder
  * @param $callback
  * @param int|null $limit
  * @param int $maxAttempts
  * @throws DBALWalkerException
  * @throws DBALException
  */
 public function run(QueryBuilder $queryBuilder, $callback, $limit = null, $maxAttempts = 10)
 {
     if (!is_callable($callback)) {
         throw new DBALWalkerException('$callback is not callable');
     }
     if (!is_null($limit)) {
         $queryBuilder->setMaxResults($limit);
     } else {
         $limit = $queryBuilder->getMaxResults();
     }
     if (is_null($limit)) {
         $limit = PHP_INT_MAX;
     }
     $offset = 0;
     do {
         $rows = [];
         $errors = $maxAttempts;
         while (true) {
             try {
                 $rows = $queryBuilder->setFirstResult($offset)->execute()->fetchAll();
                 break;
             } catch (DBALException $e) {
                 if ($errors-- == 0) {
                     throw $e;
                 }
                 $queryBuilder->getConnection()->connect();
             }
         }
         call_user_func($callback, $rows, $offset, $limit);
         $offset += $limit;
     } while (count($rows) >= $limit);
 }
All Usage Examples Of Doctrine\DBAL\Query\QueryBuilder::setFirstResult