Bug #69046 [NEW]: Die(MySQLi->Insert_Id) Doesn't Work
| From: | matthewcomp at hotmail dot com | Date: | Thu, 12 Feb 2015 22:07:11 +0000 |
| Subject: | Bug #69046 [NEW]: Die(MySQLi->Insert_Id) Doesn't Work | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-190637@lists.php.net to get a copy of this message | ||
From: matthewcomp at hotmail dot com
Operating system: Linux
PHP version: Irrelevant
Package: MySQLi related
Bug Type: Bug
Bug description:Die(MySQLi->Insert_Id) Doesn't Work
Description:
------------
I have a script which is supposed to insert a query into a database, and
output the insert ID if the operation is successful. (It's a very simple
piece of an AJAX framework.)
My MySQL handler is called $sql.
If I put:
die($sql->insert_id);
The output is empty. I expect the Insert ID to be outputted before the
script ends.
This code works fine:
echo $sql->insert_id;
die();
Test script:
---------------
$sql = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($sql->connect_error) {
die('Connect Error ('.$sql->connect_errno.')
'.$sql->connect_error);
}
$day = $_REQUEST['day'];
$content = $_REQUEST['content'];
if ($day != "-1" && $day != "0" && $day < 1) {
die("Invalid Day!");
}
if (strlen($content) < 10) {
die("Content Too Short!");
} else if (strlen($content) > 255) {
die("Content Too Long!");
}
$query = "INSERT INTO task (name, day_id, type, last, time) VALUES
('".$sql->escape_string($content)."', ".($day-0).", 0,
".time().",
".time().");";
//echo $query;
if ($sql->query($query)) {
//Return Item ID:
die($sql->insert_id);
} else {
die("MySQL Error! ".$query." - ".$sql->error);
}
Expected result:
----------------
Empty page. (No output.)
Actual result:
--------------
Insert ID for query. (ie 213.)
--
Edit bug report at https://bugs.php.net/bug.php?id=69046&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69046&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69046&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69046&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69046&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69046&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69046&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69046&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69046&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69046&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69046&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69046&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69046&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69046&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69046&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69046&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69046&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69046&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69046&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69046&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69046&r=mysqlcfg