PHP PDO lastInsertId Function and Race Status

Suppose that on my system user U1 creates a new database record in table A , and I use the lastInsertId function to get the identifier (auto_increment) of such a record, but almost at the same time (a little later) another user U2 does the same .

In this case, lastInsertId returns U1 the identifier of the record added by another user, since it is the last?

Thanks.

+6
source share
1 answer

I believe that you only need to worry about racing conditions if you use the same connection for different streams. If you use a different connection for each request, you should be fine. Checkout http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html for more details.

+3
source

All Articles