note 114174 added to mysqli.insert-id

From: Date: Mon, 20 Jan 2014 12:37:16 +0000
Subject: note 114174 added to mysqli.insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-198287@lists.php.net to get a copy of this message
Hi Dears, msqli_insert_id() simply does not ALWAYS return the correct value. Use it only, if you performed some inserts just before. Then you get what you want. In all other cases: may be, may be not. I never found out why and why not. I'm now performing a query like this: SELECT MAX(id) FROM table (by calling mysqli_query() in procedural style, for OO may be similar.) It' s simple and reliable - if you have set your id colum to "auto-increment". (if not: hm, why not??); ---- Server IP: 87.106.1.137 Probable Submitter: 94.134.219.136 ---- Manual Page -- http://php.net/manual/en/mysqli.insert-id.php Edit -- https://master.php.net/note/edit/114174 Del: integrated -- https://master.php.net/note/delete/114174/integrated Del: useless -- https://master.php.net/note/delete/114174/useless Del: bad code -- https://master.php.net/note/delete/114174/bad+code Del: spam -- https://master.php.net/note/delete/114174/spam Del: non-english -- https://master.php.net/note/delete/114174/non-english Del: in docs -- https://master.php.net/note/delete/114174/in+docs Del: other reasons-- https://master.php.net/note/delete/114174 Reject -- https://master.php.net/note/reject/114174 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198287) next »