問題描述
我對 Php PDO 函數(shù)有點(diǎn)困惑:lastInsertID.如果我理解正確,它會返回插入到數(shù)據(jù)庫中的最后一個自動增量 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.
當(dāng)我在創(chuàng)建注冊用戶的功能時執(zhí)行在我的數(shù)據(jù)庫中插入用戶的查詢時,我通常會使用此函數(shù).
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.
我的問題是,例如,我有一百個人同時在我的網(wǎng)站上注冊.并且可能是一個用戶在另一個用戶之后一毫秒點(diǎn)擊了注冊"按鈕.那么這個函數(shù)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?
可能是我想問的是服務(wù)器是否一次處理一個請求并一次處理一個 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?
請告訴我這件事.
謝謝.
推薦答案
完全安全.沒有競爭條件.它只從進(jìn)行插入的 pdo 對象返回最后插入的 Id.
Perfectly safe. There is no race condition. It only returns the last inserted Id from the pdo object that made the insert.
這篇關(guān)于Php PDO 功能有多安全:lastInsertId?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!