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

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

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

      1. Doctrine2 插入和检索新的插入 ID

        时间:2023-08-19

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

          <legend id='F6DuQ'><style id='F6DuQ'><dir id='F6DuQ'><q id='F6DuQ'></q></dir></style></legend>
          <tfoot id='F6DuQ'></tfoot>

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

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

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

                  问题描述

                  在 Doctrine2 中使用类似的东西:

                  In Doctrine2 using some thing like:

                  $user = array('username' => 'example', 'passsword' => 'changeme');
                  
                  $conn->insert('users', $user);
                  

                  然后我将如何获得我刚刚插入的用户的最后一个 ID?如果无法做到这一点,那么您如何生成 id 以便您可以执行以下操作:

                  How would I then get the last ID of the user I just inserted? If it is not possible to do this then how do you gen a id so that you can the following:

                  $id = //something here.
                  $user = array('username' => 'example', 'passsword' => 'changeme', 'id' => $id);
                  $conn->insert('users', $user);
                  

                  推荐答案

                  如果你使用的是 ORM

                  If you are using the ORM

                  $em->persist($object);
                  $em->flush();
                  $object->getId();
                  

                  如果您使用的是 DBAL:

                  if you are using the DBAL:

                  $conn->lastInsertId();
                  

                  http://www.Doctrine-project.org/api/dbal/2.5/class-Doctrine.DBAL.Connection.html#_lastInsertId

                  这篇关于Doctrine2 插入和检索新的插入 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:需要帮助理解 Doctrine 多对多自引用代码 下一篇:如何在不加入doctrine2的情况下获得id?

                  相关文章

                  <tfoot id='7tSqk'></tfoot>

                2. <i id='7tSqk'><tr id='7tSqk'><dt id='7tSqk'><q id='7tSqk'><span id='7tSqk'><b id='7tSqk'><form id='7tSqk'><ins id='7tSqk'></ins><ul id='7tSqk'></ul><sub id='7tSqk'></sub></form><legend id='7tSqk'></legend><bdo id='7tSqk'><pre id='7tSqk'><center id='7tSqk'></center></pre></bdo></b><th id='7tSqk'></th></span></q></dt></tr></i><div id='7tSqk'><tfoot id='7tSqk'></tfoot><dl id='7tSqk'><fieldset id='7tSqk'></fieldset></dl></div>
                3. <legend id='7tSqk'><style id='7tSqk'><dir id='7tSqk'><q id='7tSqk'></q></dir></style></legend>

                  1. <small id='7tSqk'></small><noframes id='7tSqk'>

                    • <bdo id='7tSqk'></bdo><ul id='7tSqk'></ul>