Bug #69714 [NEW]: insert_id does not return id
From: markem at sim1 dot us
Operating system: Windows 7
PHP version: 5.5.25
Package: MySQLi related
Bug Type: Bug
Bug description:insert_id does not return id
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 bug report at https://bugs.php.net/bug.php?id=69714&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69714&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69714&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69714&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69714&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69714&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69714&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69714&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69714&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69714&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69714&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69714&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69714&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69714&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69714&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69714&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69714&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69714&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69714&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69714&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69714&r=mysqlcfg
Thread (5 messages)
- markem at sim1 dot us