Is it possible for mysqli_insert_id to return an incorrect id in high traffic applications?

好久不见. 提交于 2019-11-28 01:57:04

No. mysqli_insert_id returns the most the AUTO_INCREMENT value from the most recent INSERT query on the current connection. It will never get confused with another connection, for example.

No. How can I be so sure? Because it would gave been reported and fixed a long time ago.

Quoting from a previous answer to this exact same question:

Look at http://dev.mysql.com/doc/refman/5.6/en/getting-unique-id.html for more information, it says this:

"For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed."

So you should be fine doing what you want and you shouldn't get strange results.

Yes it is posible! If you have multiple tables to insert with same connection and your last insert was incorrect (like I trying insert unescaped quotes in text).

I think it returns last successful insert id which can by from different table. I just spent hour to find this. Peace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!