MySQL and the chance of the wrong id being returned by LAST_INSERT_ID()

♀尐吖头ヾ 提交于 2019-11-30 17:37:54

Is that the last insert statement run on your connection or...

The last_insert on your connection.

Would PHP's mysql_insert_id() be a better solution

No, it's the same.

or should I just query for data that was just inserted and grab id that way?

That's way way slower

Link: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

Quote from that link:

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.

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