我想知道在mysql查询后获取最后一个插入ID的最佳解决方案是什么?
我找到了以下解决方案:
甚至使用mysql_insert_id php函数,但显然这个函数不能很好地与bigint(这就是我用于ID字段)和如果有很多连续的sql查询它可能是不可靠的.
有人能提供可靠而快速的解决方案来完成这项任务吗?
最佳答案
SELECT LAST_INSERT_ID()不可靠且足够安全吗?
来自MySQL Doc: 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.
来自论坛的说明: (…)All bets are off,though,if for some reason you are using persistent connections,such as via mysql_pconnect()(…)
(编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|