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

  • <small id='Wz5tx'></small><noframes id='Wz5tx'>

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

      1. 为什么 mysqli_insert_id() 总是返回 0?

        时间:2023-07-30

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

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

                • 本文介绍了为什么 mysqli_insert_id() 总是返回 0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有以下代码.mysqli_insert_id()(在本例中为$last_row"),它应该返回表的最后一行,总是返回 0.为什么会这样?

                  I have the following code. The mysqli_insert_id() (in this case "$last_row"), which is supposed to return the last row of the table, is always returning 0. Why is it so?

                  <?php
                  
                  include 'connect-db.php';
                  $last_row = mysqli_insert_id($connection);
                  
                  if ($content != '') {
                      $sql = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)";
                  
                      if (!mysqli_query($connection, $sql)) {
                          die('Error: ' . mysqli_error($connection));
                      }
                  
                      echo $last_row;
                      mysqli_close($connection);
                  }
                  

                  推荐答案

                  mysqli_insert_id 确实返回表最后一行的 ID.从文档,它:

                  mysqli_insert_id does not return the ID of the last row of the table. From the docs, it:

                  ...返回对具有 AUTO_INCREMENT 属性的列的表的查询生成的 ID.如果最后一个查询不是 INSERTUPDATE 语句,或者如果修改后的表没有具有 AUTO_INCREMENT 属性的列,则此函数将返回零.

                  ...returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn't an INSERT or UPDATE statement or if the modified table does not have a column with the AUTO_INCREMENT attribute, this function will return zero.

                  (我的重点)

                  也就是说,如果您在自动生成 ID 的插入操作之后立即运行它,那么在您进行插入操作的同一个连接上,它将返回为该插入操作生成的 ID.

                  That is, if you were to run it immediately after an insert that auto-generated an ID, on the same connection you did the insert with, it would return the ID generated for that insert.

                  上面链接的文档中的示例说明了这一点:

                  This is illustrated by the example in the docs linked above:

                  $query = "INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)";
                  $mysqli->query($query);
                  
                  printf ("New Record has id %d.
                  ", $mysqli->insert_id);
                  

                  这篇关于为什么 mysqli_insert_id() 总是返回 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我应该什么时候关闭 PHP 中的数据库连接? 下一篇:PHP到EasyPHP MySQL服务器1秒连接延迟

                  相关文章

                  最新文章

                  • <bdo id='gGJWe'></bdo><ul id='gGJWe'></ul>

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

                  1. <small id='gGJWe'></small><noframes id='gGJWe'>

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