Bug #69046 [Opn->Nab]: Die(MySQLi->Insert_Id) Doesn't Work

From: Date: Thu, 12 Feb 2015 22:34:11 +0000
Subject: Bug #69046 [Opn->Nab]: Die(MySQLi->Insert_Id) Doesn't Work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190640@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69046&edit=1 ID: 69046 Updated by: requinix@php.net Reported by: matthewcomp at hotmail dot com Summary: Die(MySQLi->Insert_Id) Doesn't Work -Status: Open +Status: Not a bug Type: Bug Package: MySQLi related Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Remembering that die() is an alias of exit(), http://php.net/manual/en/function.exit.php >If status is an integer, that value will be used as the exit status and not >printed. Previous Comments: ------------------------------------------------------------------------ [2015-02-12 22:33:05] phpmpan at mpan dot pl NaB Please read documentation for die (or exit), especially on meaning of its argument depending on argument's type. ------------------------------------------------------------------------ [2015-02-12 22:07:10] matthewcomp at hotmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=69046&edit=1

« previous php.bugs (#190640) next »