From: shaneperc at gmail dot com Operating system: Linux 2.6.9 PHP version: 5.2.5 PHP Bug Type: MySQLi related Bug description: mysqli_insert_id results
Description: ------------ $mysqli->insert_id is returning nothing. I tried mysqli_insert_id($mysqli) as well with the same result. You've heard this before, BUT, I found a reproducible fix. I found that by concatenating an empty string to the scalar that holds the id, it's then accessible. In the code below, if the commented line is uncommented, everything works as expected. Without adding the empty string, it doesn't work. (and testing the value doesn't work at all). I hope this is helpful to someone who can fix this. Reproduce code: --------------- $id = (is_numeric($_POST['staff_id'])) ? $_POST['staff_id'] : "new"; if($id == "new"){ if(!$db->query("INSERT INTO staff() VALUES()")){ die("Couldn't insert a new staffer: " . $db->error); } $id = $db->insert_id; if(!$id){ die("<h2>IDs are acting up again! Tell Shane and don't use this again until further notice</h2>"); } } /*$id = $id . ""; -----uncommenting this will make it work-----*/ die($id); Expected result: ---------------- Expect to see ID number (either one already set, or the newly generated one). BTW, if $_POST['staff_id'] doesn't require the insert, this works everytime as expected. Actual result: -------------- Nothing on screen, nothing in the generated source. -- Edit bug report at http://bugs.php.net/?id=44302&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44302&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44302&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44302&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44302&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44302&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44302&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44302&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44302&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44302&r=support Expected behavior: http://bugs.php.net/fix.php?id=44302&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44302&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44302&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44302&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44302&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44302&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44302&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44302&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44302&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44302&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44302&r=mysqlcfg