Should I use Connection::executeUpdate()?

2.1k Views Asked by At

I use Doctrine DBAL v2.5.0 and I would like to perform a simple update statement. In the documentation it is written that I should use the method executeUpdate() (http://doctrine-dbal.readthedocs.org/en/latest/reference/data-retrieval-and-manipulation.html#executeupdate) for that. But in the source code this method has the annotation @internal. Because of that I am not sure whether this method should be used from non-library code or not. Should I?

1

There are 1 best solutions below

1
On

It seems that you have to use the executeUpdate() method on the doctrine service and not on the entity manager.

$this->container->get('doctrine.orm.entity_manager')->getConnection()->executeUpdate($query); gives a warning in my IDE that executeUpdate() is @internal.

$this->container->get('doctrine')->getConnection()->executeUpdate($query); or in a controller $this->getDoctrine()->getConnection()->executeUpdate($query); does not give any warning.

With other words: You want to call the executeUpdate() method on \Doctrine\Bundle\DoctrineBundle\Registry class instead of the \Doctrine\ORM\EntityManager class

P.D. Maybe I should mention that I am using Doctrine in conjunction with Symfony2.