<i id='RYcSO'><tr id='RYcSO'><dt id='RYcSO'><q id='RYcSO'><span id='RYcSO'><b id='RYcSO'><form id='RYcSO'><ins id='RYcSO'></ins><ul id='RYcSO'></ul><sub id='RYcSO'></sub></form><legend id='RYcSO'></legend><bdo id='RYcSO'><pre id='RYcSO'><center id='RYcSO'></center></pre></bdo></b><th id='RYcSO'></th></span></q></dt></tr></i><div id='RYcSO'><tfoot id='RYcSO'></tfoot><dl id='RYcSO'><fieldset id='RYcSO'></fieldset></dl></div>
        <tfoot id='RYcSO'></tfoot>
        • <bdo id='RYcSO'></bdo><ul id='RYcSO'></ul>

        <small id='RYcSO'></small><noframes id='RYcSO'>

      1. <legend id='RYcSO'><style id='RYcSO'><dir id='RYcSO'><q id='RYcSO'></q></dir></style></legend>

        Doctrine2 ORM 选择更新

        时间:2024-08-09
        • <bdo id='TUCEa'></bdo><ul id='TUCEa'></ul>
          <i id='TUCEa'><tr id='TUCEa'><dt id='TUCEa'><q id='TUCEa'><span id='TUCEa'><b id='TUCEa'><form id='TUCEa'><ins id='TUCEa'></ins><ul id='TUCEa'></ul><sub id='TUCEa'></sub></form><legend id='TUCEa'></legend><bdo id='TUCEa'><pre id='TUCEa'><center id='TUCEa'></center></pre></bdo></b><th id='TUCEa'></th></span></q></dt></tr></i><div id='TUCEa'><tfoot id='TUCEa'></tfoot><dl id='TUCEa'><fieldset id='TUCEa'></fieldset></dl></div>
          • <tfoot id='TUCEa'></tfoot>

            <legend id='TUCEa'><style id='TUCEa'><dir id='TUCEa'><q id='TUCEa'></q></dir></style></legend>

              <small id='TUCEa'></small><noframes id='TUCEa'>

                  <tbody id='TUCEa'></tbody>

                  本文介绍了Doctrine2 ORM 选择更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  您能否建议一种如何使用 Doctrine 实现 SELECT FOR UPDATE 的方法?

                  Could you suggest an approach how to implement SELECT FOR UPDATE with Doctrine?

                  我需要读取一个计数器值,然后在 PHP 代码中使用它,并在其他人(来自另一个进程)使用相同的值之前立即递增该值.

                  I need to read a counter value, then use it in PHP code and immediately increment the value before someone else (from another process) uses the same value.

                  推荐答案

                  锁定支持

                  Doctrine 2 实现 对实体的锁定支持:

                  <?php
                  use DoctrineDBALLockMode;
                  use DoctrineORMOptimisticLockException;
                  
                  $theEntityId = 1;
                  $expectedVersion = 184;
                  
                  try {
                      $entity = $em->find('User', $theEntityId, LockMode::OPTIMISTIC, $expectedVersion);
                  
                      // do the work
                  
                      $em->flush();
                  } catch(OptimisticLockException $e) {
                      echo "Someone else has already changed this entity. Apply the changes again!";
                  }
                  

                  本机 sql

                  另外,你可以抛出执行原始 SQL:

                  Native sql

                  Also, you can do it throws execute raw SQL:

                  $em->getConnection()->exec('LOCK TABLES table_name WRITE;'); //lock for write access
                  

                  然后

                  $em->getConnection()->exec('UNLOCK TABLES;');
                  

                  这篇关于Doctrine2 ORM 选择更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在循环中执行 Doctrine 查询时的内存泄漏 下一篇:在 Symfony2/Doctrine SQL 中使用 JOIN

                  相关文章

                  <i id='HAZ96'><tr id='HAZ96'><dt id='HAZ96'><q id='HAZ96'><span id='HAZ96'><b id='HAZ96'><form id='HAZ96'><ins id='HAZ96'></ins><ul id='HAZ96'></ul><sub id='HAZ96'></sub></form><legend id='HAZ96'></legend><bdo id='HAZ96'><pre id='HAZ96'><center id='HAZ96'></center></pre></bdo></b><th id='HAZ96'></th></span></q></dt></tr></i><div id='HAZ96'><tfoot id='HAZ96'></tfoot><dl id='HAZ96'><fieldset id='HAZ96'></fieldset></dl></div>

                  1. <legend id='HAZ96'><style id='HAZ96'><dir id='HAZ96'><q id='HAZ96'></q></dir></style></legend>
                    1. <small id='HAZ96'></small><noframes id='HAZ96'>

                      <tfoot id='HAZ96'></tfoot>

                        <bdo id='HAZ96'></bdo><ul id='HAZ96'></ul>