note 90001 added to mysqli.insert-id

From: Date: Wed, 01 Apr 2009 15:27:21 +0000
Subject: note 90001 added to mysqli.insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-152706@lists.php.net to get a copy of this message
Note that if you Call a MySQL stored procedure to insert a new record and then reference $db->insert_id; you will get 0 back, not the last inserted ID. It is therefore necessary to add a line to your MySQL Stored Procedure such as select last_insert_id() as intRecordKey; after the insert so that the query will return the new key value. Then in your php code you can use the following <?php $objInsertResult = $db->query($strSQL); $objInsertRow = $objInsertResult->fetch_object(); $intRecordKey = $objInsertRow->intRecordKey; ?> It would however be nice if $db->insert_id did return the last insert ID following a stored procedure call. ---- Server IP: 92.48.74.199 Probable Submitter: 90.202.78.75 ---- Manual Page -- http://www.php.net/manual/en/mysqli.insert-id.php Edit -- https://master.php.net/note/edit/90001 Del: integrated -- https://master.php.net/note/delete/90001/integrated Del: useless -- https://master.php.net/note/delete/90001/useless Del: bad code -- https://master.php.net/note/delete/90001/bad+code Del: spam -- https://master.php.net/note/delete/90001/spam Del: non-english -- https://master.php.net/note/delete/90001/non-english Del: in docs -- https://master.php.net/note/delete/90001/in+docs Del: other reasons-- https://master.php.net/note/delete/90001 Reject -- https://master.php.net/note/reject/90001 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152706) next »