Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 理论上的第一个结果引起了问题_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 理论上的第一个结果引起了问题

Php 理论上的第一个结果引起了问题,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我有以下疑问: $em = $this->getEntityManager(); $query = $em->createQueryBuilder()->select('p') ->from("AppMainBundle:ShopPicture", 'p') ->innerJoin('p.shop', 's') ->an

我有以下疑问:

  $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;
      }
我基本上想得到照片的X剩余偏移量。例如,如果一家商店有15张图片,偏移量是5,那么我想从这个查询中得到5张最旧的图片。但是,这给了我一个错误:

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

知道为什么吗?

对于MySQL,您还需要一个限制子句,而不仅仅是偏移量。在您的情况下,添加

$query->setMaxResults($limit);
然后它就会起作用。如果你真的不想要这个限制,就把它设为一个非常高的数字


对于MySQL,您还需要一个limit子句,而不仅仅是偏移量。在您的情况下,添加

$query->setMaxResults($limit);
然后它就会起作用。如果你真的不想要这个限制,就把它设为一个非常高的数字


能否显示日志文件中的实际查询?@AjeetManral添加的实际查询能否显示日志文件中的实际查询?@AjeetManral添加的实际查询