|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-02-12 22:33 UTC] phpmpan at mpan dot pl
[2015-02-12 22:34 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2015-02-12 22:34 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 19:00:02 2025 UTC |
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.)