学说中的setFirstResult导致问题

I have the following query:

  $em = $this->getEntityManager();
      $query = $em->createQueryBuilder()->select('p')
                     ->from("AppMainBundle:ShopPicture", 'p')
                     ->innerJoin('p.shop', 's')
                     ->andWhere('s.id = :shopId ')
                     ->setParameter('shopId', $shopId)
                     ->orderBy('p.created', 'DESC')
                     ;

      $result =  $query->getQuery()->getResult();
      if (count($result) > $offset) {
          $query->setFirstResult($offset);
          $result =  $query->getQuery()->getResult();
      } else {
          $result = NULL;
      }

I basically wanted to get the X remaining offsets of pictures. So for example if a shop has 15 pictures and offset is 5, then I wanted to get the 5 oldest picture from this query. However this gives me the error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 10' at line 1

Any idea why?

For MySQL, you need to have a limit clause as well, not just the offset. In your case, add

$query->setMaxResults($limit);

and then it should work. If you don't really want the limit, set it to a really high number.

http://dev.mysql.com/doc/refman/5.0/en/select.html