Why is mysqli_insert_id() always returning 0?

前端 未结 4 2022
醉话见心
醉话见心 2020-12-01 14:37

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?

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 15:16

    For other people coming here, maybe you tried INSERT IGNORE INTO and you have a UNIQUE value that was already inserted. In that case, this id is zero.

    Also you'll get "zero" if MySQL runs out of connections. I'm no expert on persistent connections but this might help somebody?

    As you probably know PHP “mysql” extension supported persistent connections but they were disabled in new “mysqli” extension --Peter Zaitsev

提交回复
热议问题