Doctrine2 ORM select for update
问题 Please could you suggest me some approach how to implement SELECT FOR UPDATE with Doctrine? I need to read some counter value, use it in PHP code and immediately increment the value before someone else (from another process) uses the same value. 回答1: Locking support Doctrine 2 implements Locking support for entities: <?php use Doctrine\DBAL\LockMode; use Doctrine\ORM\OptimisticLockException; $theEntityId = 1; $expectedVersion = 184; try { $entity = $em->find('User', $theEntityId, LockMode: