使用php在mysql中查找最后插入的ID的最佳方法

我想知道在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()(…)

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。