note 128122 added to mysqli.insert-id
| From: | adrian dot nesse dot wiik at gmail dot com | Date: | Wed, 18 Jan 2023 10:05:01 +0000 |
| Subject: | note 128122 added to mysqli.insert-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220077@lists.php.net to get a copy of this message | ||
If you try to INSERT a row using ON DUPLICATE KEY UPDATE, be aware that insert_id will not update if
the ON DUPLICATE KEY UPDATE clause was triggered.
When you think about it, it's actually very logical since ON DUPLICATE KEY UPDATE is an UPDATE
statement, and not an INSERT.
In a worst case scenario, if you're iterating over something and doing INSERTs while relying on
insert_id in later code, you could be pointing at the wrong row on iterations where ON DUPLICATE KEY
UPDATE is triggered!
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.158.213 (proxied: 62.50.172.211)
----
Manual Page -- https://php.net/manual/en/mysqli.insert-id.php
Edit -- https://main.php.net/note/edit/128122
Del: integrated -- https://main.php.net/note/delete/128122/integrated
Del: useless -- https://main.php.net/note/delete/128122/useless
Del: bad code -- https://main.php.net/note/delete/128122/bad+code
Del: spam -- https://main.php.net/note/delete/128122/spam
Del: non-english -- https://main.php.net/note/delete/128122/non-english
Del: in docs -- https://main.php.net/note/delete/128122/in+docs
Del: other reasons-- https://main.php.net/note/delete/128122
Reject -- https://main.php.net/note/reject/128122
Search -- https://main.php.net/manage/user-notes.php