Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use prepare statement in doctrine ORM

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

like image 516
Mirage Avatar asked Feb 18 '26 18:02

Mirage


1 Answers

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.

like image 107
chiborg Avatar answered Feb 21 '26 13:02

chiborg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!