I'm using the Yii PHP framework which has a function PDO::lastInsertId that's apparently just an implementation of PDO::lastInsertId. If my application has very rapid inserts from possibly thousands of simultaneous users, will this function be reliable to get the Auto-incremented row ID of the data I just inserted?
I need to get the id of the row I just inserted to do a bit of work after the insert itself, but want to make sure that if the insert rate is very high, it wont cause inconsistent results.
Thanks!
yes, of course, no worries about that, but you've to make sure to ask the lastInsertId just after the insert query. No other query should be executed on that connection in the meantime, each PHP process must have a separate connection.
Also if you think that a table is going to have hundreds or thousands of insert per second, consider to not use indexes or use the minimum amount of indexes. In case of MySQL favour MyISAM tables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With