|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68383 more_results() && next_result() doesn't work right
Submitted: 2014-11-09 17:49 UTC Modified: 2020-11-26 11:58 UTC
From: anatoliy at ukhvanovy dot name Assigned: nikic (profile)
Status: Closed Package: MySQLi related
PHP Version: Irrelevant OS: windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: anatoliy at ukhvanovy dot name
New email:
PHP Version: OS:


 [2014-11-09 17:49 UTC] anatoliy at ukhvanovy dot name
From manual page:
There is an example in this documentation page:
$sql = "SELECT COUNT(*) AS _num FROM test; ";
$sql.= "INSERT INTO test(id) VALUES (1); ";
$sql.= "SELECT COUNT(*) AS _num FROM test; ";
do {
	if ($res = $mysqli->store_result()) {
} while ($mysqli->more_results() && $mysqli->next_result());
This is wrong example! If an error occurs while executing this query - then you will never know about it! Because, if error occurs in some SQL-statement, more_results() will return true, but next_result() will return false, and therefore the whole while-expression «$mysqli->more_results() && $mysqli->next_result()» will evaluate to false and the loop will simply stop as if there isn't any error!
Look at example below. 
(watch «test script»)
Try the following code instead of while-loop. In this code (below) throws exception, as it should be.
for ($iterate = true; $iterate; ($iterate = $mysqli->more_results()) && $mysqli->next_result()) {
	$res = $mysqli->store_result();
	if($res === false) continue;

Test script:
$driver = new mysqli_driver();

$mysqli = new mysqli("localhost", "root", null, "my_db");

$sql = <<<'EOF'
SELECT COUNT(*) AS _num FROM my_tbl;
SELECT COUNT(*) AS _num FROM my_tbl;

if (!$mysqli->multi_query($sql)) {
	echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;

do {
	if ($res = $mysqli->store_result()) {
} while ($mysqli->more_results() && $mysqli->next_result());

Expected result:
This code should warn me about an error in line "SYNTAX ERROR! INSERT INTO my_tbl() VALUES ();". I've set report mode to MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT, so that an exception should be thrown. 

Actual result:
But this doesn't happen! This code just gets next_result == false and doesn't even try to execute store_result()! And if this code would try to do so, an exception would be thrown, but this doesn't happen.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-28 12:48 UTC]
-Package: Documentation problem +Package: MySQLi related
 [2020-11-26 11:58 UTC]
-Status: Open +Status: Closed -Type: Documentation Problem +Type: Bug -Assigned To: +Assigned To: nikic
 [2020-11-26 11:58 UTC]
This should be fixed by The lack of error reporting was a bug in PHP, not just a doc problem.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Dec 05 03:01:23 2020 UTC