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

      How to get the id of a row i#39;ve just inserted php/mysql(如何获取我刚刚插入 php/mysql 的行的 id)
      <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 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>
                    <tbody id='cHBTc'></tbody>
                    <bdo id='cHBTc'></bdo><ul id='cHBTc'></ul>
                        <tfoot id='cHBTc'></tfoot>
                        • <small id='cHBTc'></small><noframes id='cHBTc'>

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