Estimated reading time: 1 minute
Posted on August 25, 2013

Extending Doctrine2 Connection Class

Hey! Here’s a tiny and quick tutorial on how to extend Doctrine2 connection class with custom methods.

You may find yourself in lots of situations where it can come in quite handy.

In our case, a few queries got regularly locked by other queries running simultaneously.

Since those queries were performing in admin panel, we did not want to spend time resolving locks. Instead, we wanted a method for a query retry in case of locking failures.

What you really need to do is create a new connection class inherited from the standard connection class.

And then you just need to tell Doctrine to use your class instead of the default one:

As simple as that!

BTW, you can check out this class and some other Doctrine2 additions on our doctrine-extensions GitHub repository.