如何使用内部联接创建查询构建器更新
How to create a query builder update with inner join
我有这个问题:
$query = $this->_em->createQuery(
"UPDATE PublicBundle:Table1 t1
JOIN PublicBundle:Table2 t2 WITH t1.ad_id = t2.id
SET t1.status = :status
WHERE t1.status IN (':statuses')
AND t2.updated_at < ':dateLimit'"
)->setParameter('status', 1)
->setParameter('statuses', implode(",", $statuses))
->setParameter('dateLimit', new \DateTime(sprintf('-%d day', $date))
echo $query->getSQL();
$query->execute();
但是我得到了错误:
Error: Expected Doctrine\ORM\Query\Lexer::T_EQUALS, got 't2');
你能帮帮我吗?提前致谢
$sql ="UPDATE Table1 t1
JOIN Table2 t2 ON t1.ad_id = t2.id
SET t1.status = :status
WHERE t1.status IN (':statuses')
AND t2.updated_at < ':dateLimit'";
$params=array(
'status'=>1,
'statuses'=> implode(",", $statuses)
'dateLimit'=>new \DateTime(sprintf('-%d day', $date)
);
return $this->getEntityManager()->getConnection()->executeQuery($sql, $params);
尝试在您的自定义 repository.First 中使用它,在您的 phpmyadmin 中进行硬编码,然后在您的脚本中尝试 sql
我有这个问题:
$query = $this->_em->createQuery(
"UPDATE PublicBundle:Table1 t1
JOIN PublicBundle:Table2 t2 WITH t1.ad_id = t2.id
SET t1.status = :status
WHERE t1.status IN (':statuses')
AND t2.updated_at < ':dateLimit'"
)->setParameter('status', 1)
->setParameter('statuses', implode(",", $statuses))
->setParameter('dateLimit', new \DateTime(sprintf('-%d day', $date))
echo $query->getSQL();
$query->execute();
但是我得到了错误:
Error: Expected Doctrine\ORM\Query\Lexer::T_EQUALS, got 't2');
你能帮帮我吗?提前致谢
$sql ="UPDATE Table1 t1
JOIN Table2 t2 ON t1.ad_id = t2.id
SET t1.status = :status
WHERE t1.status IN (':statuses')
AND t2.updated_at < ':dateLimit'";
$params=array(
'status'=>1,
'statuses'=> implode(",", $statuses)
'dateLimit'=>new \DateTime(sprintf('-%d day', $date)
);
return $this->getEntityManager()->getConnection()->executeQuery($sql, $params);
尝试在您的自定义 repository.First 中使用它,在您的 phpmyadmin 中进行硬编码,然后在您的脚本中尝试 sql