我可以在学说ORM中使用prepare语句吗?

我可以在学说ORM中使用prepare语句吗?

问题描述:

I am using this code

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;

    }

Now setParametr and bindValue thing is not working. However if i just put isActive=1 , then it works

我正在使用此代码 p>

  public function addTasks()  
 {
 $ stmt = $ this-> getEntityManager()
  - > getConnection()
  - > prepare('INSERT into newTasks(tasks_id,Profile_id)
 SELECT task.id,3 as Profile_id  
 
 FROM ptasks,其中ptasks.isActive =:mid'); 
 
 
 $ stmt  - > setParameter('mid',1); 
 // $ stmt-> bindValue('foobar',1  ); 
 $ stmt-> execute(); 
返回true; 
 
} 
  code>  pre> 
 
 

现在 setParametr code>和 bindValue code>的东西不起作用。 但是,如果我只是把 isActive = 1 code>,那么它可以工作 p> div>

You need to add a colon in front of the parameter like this:

$stmt->setParameter(':mid',1);

This is the difference between the PDO connection driver implementation and Doctrine setParameter function where the colon is not needed.