note 76504 added to function.mysql-insert-id

From: Date: Wed, 18 Jul 2007 15:35:16 +0000
Subject: note 76504 added to function.mysql-insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-128691@lists.php.net to get a copy of this message
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() ---- Server IP: 216.235.15.211 Probable Submitter: 192.206.151.130 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php Edit -- https://master.php.net/note/edit/76504 Del: integrated -- https://master.php.net/note/delete/76504/integrated Del: useless -- https://master.php.net/note/delete/76504/useless Del: bad code -- https://master.php.net/note/delete/76504/bad+code Del: spam -- https://master.php.net/note/delete/76504/spam Del: non-english -- https://master.php.net/note/delete/76504/non-english Del: in docs -- https://master.php.net/note/delete/76504/in+docs Del: other reasons-- https://master.php.net/note/delete/76504 Reject -- https://master.php.net/note/reject/76504 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128691) next »