我正在使用这个代码
public function addTasks()
{
$stmt = $this->getEntityManager()
->getConnection()
->prepare('INSERT into newTasks (tasks_id, Profile_id)
SELECT task.id, 3 as Profile_id
FROM ptasks where ptasks.isActive = :mid');
$stmt ->setParameter('mid',1);
//$stmt->bindValue('foobar ', 1);
$stmt->execute();
return true;
}
现在 setParametr
和 bindValue
不起作用。但是,如果我只是输入 isActive=1
,那么它就可以工作了
最佳答案
需要在参数前加一个冒号,如下所示:
$stmt->setParameter(':mid',1);
这是 PDO 连接驱动实现和 Doctrine setParameter
函数之间的区别,这里不需要冒号。
关于php - 我可以在学说 ORM 中使用准备语句吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823980/