1. <tfoot id='1GM1e'></tfoot>

    <legend id='1GM1e'><style id='1GM1e'><dir id='1GM1e'><q id='1GM1e'></q></dir></style></legend>

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

      <bdo id='1GM1e'></bdo><ul id='1GM1e'></ul>
  2. <small id='1GM1e'></small><noframes id='1GM1e'>

    1. 如何获取我刚刚插入 php/mysql 的行的 id

      时间:2023-10-30
      <i id='Y9e0X'><tr id='Y9e0X'><dt id='Y9e0X'><q id='Y9e0X'><span id='Y9e0X'><b id='Y9e0X'><form id='Y9e0X'><ins id='Y9e0X'></ins><ul id='Y9e0X'></ul><sub id='Y9e0X'></sub></form><legend id='Y9e0X'></legend><bdo id='Y9e0X'><pre id='Y9e0X'><center id='Y9e0X'></center></pre></bdo></b><th id='Y9e0X'></th></span></q></dt></tr></i><div id='Y9e0X'><tfoot id='Y9e0X'></tfoot><dl id='Y9e0X'><fieldset id='Y9e0X'></fieldset></dl></div>
        <tbody id='Y9e0X'></tbody>
    2. <legend id='Y9e0X'><style id='Y9e0X'><dir id='Y9e0X'><q id='Y9e0X'></q></dir></style></legend>

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

    3. <tfoot id='Y9e0X'></tfoot>
      • <bdo id='Y9e0X'></bdo><ul id='Y9e0X'></ul>

                本文介绍了如何获取我刚刚插入 php/mysql 的行的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Possible Duplicate:
                PHP: how to get last inserted ID of a table?

                I'm writing a function to add data do a database, but I then want to immediately use that entry in my code.

                I know I could query: SELECT id FROM table ORDER BY id DESC

                But I wonder if there's any more direct way of doing it.

                解决方案

                That mostly depends on the interface you're using to access MySQL.

                If you're using PDO (recommended), you'd use PDO::lastInsertId(): http://us.php.net/manual/en/pdo.lastinsertid.php

                If you're using MySQL, you'd use mysql_insert_id() http://php.net/manual/en/function.mysql-insert-id.php

                If you're using MySQLi, you'd use mysqli_insert_id(): http://us.php.net/manual/en/mysqli.insert-id.php

                Just simply call whichever function is appropriate right after your INSERT completes.

                It's important to note that you likely do not want to fetch id out of the database using SELECT because if you have multiple writers, you may get the id that some other thread inserted. At best, you'll operate on the wrong data, and at worst, you could have serious security issues and/or corruption.

                这篇关于如何获取我刚刚插入 php/mysql 的行的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:教义 - 只用一个 save() 插入多行 下一篇:从带有 PDO 的 SELECT 中插入 MySQL

                相关文章

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

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