Php PDO函数:lastInsertId有多安全? [英] How safe is Php PDO function: lastInsertId?

查看:68
本文介绍了Php PDO函数:lastInsertId有多安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Php PDO函数几乎没有什么困惑:lastInsertID.如果我理解正确,它将返回数据库中插入的最后一个自动增量ID.

I have little confusion about the Php PDO function: lastInsertID. If I understand correctly, it returns the last auto-incremental id that was inserted in the database.

当我创建创建用户注册功能的查询时,通常会在执行将用户插入数据库中的查询时使用此功能.

I usually use this function when I execute a query that inserts a user in my database when I am creating the functionality of registering a user.

我的问题是,例如说我有一百个人在我的网站上进行了一次注册.并且可能是一个用户在另一位用户之后的一毫秒内点击了注册"按钮.那么这个函数lastInsertId是否有可能返回刚才注册的另一个用户的ID?

My question is that say I have a hundred people registering on my site at one point for example. And may be one user hit the 'Register' button a millisecond after another user. Then is there a chance that this function lastInsertId will return the id of another user that register just momentarily earlier?

也许我想问的是服务器一次处理一个请求并一次处理一个php文件吗?

May be what I am trying to ask is does the server handle one request at a time and go through a php file one at a time?

请让我知道这一点.

谢谢.

推荐答案

完全安全.没有比赛条件.它仅返回进行插入操作的pdo对象中最后插入的ID.

Perfectly safe. There is no race condition. It only returns the last inserted Id from the pdo object that made the insert.

这篇关于Php PDO函数:lastInsertId有多安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆