我可以在学说 ORM 中使用准备语句吗

Ran*_*ngh 3 php symfony doctrine-orm

我正在使用此代码

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;

    }
Run Code Online (Sandbox Code Playgroud)

现在setParametrbindValue事情不工作。然而,如果我只是把isActive=1,那么它的工作原理

chi*_*org 5

您需要在参数前添加一个冒号,如下所示:

$stmt->setParameter(':mid',1);
Run Code Online (Sandbox Code Playgroud)

这是 PDO 连接驱动程序实现和setParameter不需要冒号的Doctrine函数之间的区别。