而不是逐个删除我的实体
$this->em->remove($price);
这是我尝试过的:
$sqlQuery = "delete from mytable where mytable.fieldone_id = ".$fieldoneid." and mytable.fieldtwo_id = ".$fieldtwoid.";"; $query = $this->getEntityManager()->createNativeQuery($sqlQuery); $query->execute();
它返回以下错误:
Catchable fatal error: Argument 2 passed to Doctrine\ORM\EntityManager::createNativeQuery() must be an instance of Doctrine\ORM\Query\ResultSetMapping,none given
它希望我传递ResultSetMapping,但它是一个删除查询…
谁能请教我怎么做?
在我看来,我使用一种更简单的执行本机SQL查询的方式.尝试这样的事情(我也使用PDO方法在查询中包含变量,这更安全):
原文链接:https://www.f2er.com/php/135364.html$sql = "delete from mytable where mytable.fieldone_id = :fieldoneid and mytable.fieldtwo_id = :fieldtwoid"; $params = array('fieldoneid'=>$fieldoneid,'fieldtwoid'=>$fieldtwoid); $em = $this->getDoctrine()->getManager(); $stmt = $em->getConnection()->prepare($sql); $stmt->execute($params); // if you are doing a select query,fetch the results like this: // $result = $stmt->fetchAll();
这对我很有用,希望它有所帮助