note 76504 deleted from function.mysql-insert-id by cmb
| From: | cmb@php.net | Date: | Sun, 16 Feb 2020 13:41:59 +0000 |
| Subject: | note 76504 deleted from function.mysql-insert-id by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214131@lists.php.net to get a copy of this message | ||
Note Submitter: guelphdad at yahoo dot com
----
and the primary reason to use neither of those last two solutions is both could result in race
conditions when there is more than a single user with access to the database. when you use MAX or
ORDER BY DESC LIMIT 1 you will retrieve the maximum value from the table, at that moment. That
doesn't mean another user doesn't do an insertion in the primary and secondary table
BEFORE you do your insertion in the secondary table. You have thus inserted a row with a correct id
into the second table. Always use last_insert_id()