Bug #69714 [Com]: insert_id does not return id

From: Date: Wed, 27 May 2015 21:09:58 +0000
Subject: Bug #69714 [Com]: insert_id does not return id
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192938@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69714&edit=1 ID: 69714 Comment by: markem at sim1 dot us Reported by: markem at sim1 dot us Summary: insert_id does not return id Status: Open Type: Bug Package: MySQLi related Operating System: Windows 7 PHP Version: 5.5.25 Block user comment: N Private report: N New Comment: I forgot to put in that this is NOT the first record in the table. It is record #60. So you need to put in a few records to see that it still returns zero each time. Previous Comments: ------------------------------------------------------------------------ [2015-05-27 21:08:06] markem at sim1 dot us Description: ------------ Situation: Inserting records in to a table. The record ID number is being inserted into the table. When this is done AND the record has been inserted THEN a call to the insert_id() function in either way (ie: $db->insert_id or mysqli_insert_id($db)) does NOT return the id number just inserted. This might seem like a dumb thing to do but I stumbled across this because the INSERT command was changed from not sending the record's ID number to setting it. In either event (setting it or not setting it) - the id number should always be returned when the call is made to the insert_id() function after an INSERT command has been sent. Test script: --------------- MySQL: Set up a simple table (called LOG) in a database with ID, Date, and Entry fields. PHP: Use a simple command to insert a record into the above table. $table = mysqli( "HOST", "USER", "PASSWORD", "DATABASE" ); $sql = "insert into log (id, date, entry) values (1,NOW(),'Test')"; $table->query( $sql ); echo "ID = " . $table->insert_id . "\n"; exit; Expected result: ---------------- ID = <Record ID> Actual result: -------------- ID = 0 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69714&edit=1

« previous php.bugs (#192938) next »