我有这个问题:
$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');
你能帮帮我吗? Thx提前
答案 0 :(得分:1)
$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);
尝试在自定义存储库中使用它。首先在phpmyadmin中对其进行硬编码,然后在脚本上尝试此sql