Is PDO :: lastInsertId reliable with very fast inserts?

I am using the Yii PHP framework, which has the PDO :: lastInsertId function, which apparently is an implementation of PDO :: lastInsertId. If my application has a very fast insertion of perhaps thousands of concurrent users, will this function be reliable to get the row identifier with automatic increment of the data that I just inserted?

I need to get the identifier of the row I just inserted in order to do a bit of work after the insert itself, but I want to make sure that if the insertion speed is very high, it will not lead to inconsistent results.

Thanks!

+4
source share
1 answer

yes, of course, don't worry about that, but you should definitely ask lastInsertId right after the insert request. At the same time, another request should not be executed on this connection, each PHP process should have a separate connection.

Also, if you think that a table will have hundreds or thousands of attachments per second, consider not using indexes or using a minimum amount of indexes. In case MySQL supports MyISAM tables.

+12
source

All Articles