简体   繁体   中英

get mysql last insert id, after inserting record using PDO

I use PDO prepared statements to insert records. And uses lastInsertId to get id of inserted record. But is this good?

Because what happens when several users insert at same time? lastInsertId will conflict in that situation? So I should use transaction?

please help

它会返回正确的ID,不用担心。

Every PHP script basically lives on its own. When several users insert at the same time, user A will get his last insert's row idA and user B will get her last insert's row idB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM