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 使用createQueryBuilder在doctrine2中使用LIMIT(setMaxResults)更新查询不工作_Php_Symfony_Doctrine Orm_Dql - Fatal编程技术网

Php 使用createQueryBuilder在doctrine2中使用LIMIT(setMaxResults)更新查询不工作

Php 使用createQueryBuilder在doctrine2中使用LIMIT(setMaxResults)更新查询不工作,php,symfony,doctrine-orm,dql,Php,Symfony,Doctrine Orm,Dql,我有以下代码 $qb = $this->createQueryBuilder('cs') ->update() ->set('cs.is_active', 1) ->where('cs.reward_coupon = :reward_coupon') ->setMaxResults($limit) ->setParameter('reward_coupon', $rewardCou

我有以下代码

$qb = $this->createQueryBuilder('cs')
        ->update()
        ->set('cs.is_active', 1)
        ->where('cs.reward_coupon = :reward_coupon')
        ->setMaxResults($limit)
        ->setParameter('reward_coupon', $rewardCoupon);
$qb->getQuery()->execute(); 
这不适用于结果查询中的限制。

setMaxResult()必须是您的最后一条条令语句才能正常工作

例如:

    $qb = $this->createQueryBuilder('cs')
    ->update()
    ->set('cs.is_active', 1)
    ->where('cs.reward_coupon = :reward_coupon')
    ->setParameter('reward_coupon', $rewardCoupon)
    ->setMaxResults($limit);


     return $qb->getQuery()->execute(); 

我想这可能会有帮助

$limit=50;
$i=0;
$qb = $this->createQueryBuilder('cs')
->update()
->set('cs.is_active', 1)
->where('cs.reward_coupon = :reward_coupon')
->setParameter('reward_coupon', $rewardCoupon)
->setFirstResult($i)
->setMaxResults($limit);
$qb->getQuery()->execute(); 

在UPDATE语句中使用时,不能为LIMIT设置起始索引。