Skip to content

Commit fe73616

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Handle errors during next_result()
2 parents fa35561 + d776c31 commit fe73616

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,11 @@ PHP_FUNCTION(mysqli_next_result) {
15521552
}
15531553
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
15541554

1555-
RETURN_BOOL(!mysql_next_result(mysql->mysql));
1555+
if (mysql_next_result(mysql->mysql)) {
1556+
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
1557+
RETURN_FALSE;
1558+
}
1559+
RETURN_TRUE;
15561560
}
15571561
/* }}} */
15581562

@@ -1583,7 +1587,11 @@ PHP_FUNCTION(mysqli_stmt_next_result) {
15831587
}
15841588
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
15851589

1586-
RETURN_BOOL(!mysql_stmt_next_result(stmt->stmt));
1590+
if (mysql_stmt_next_result(stmt->stmt)) {
1591+
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
1592+
RETURN_FALSE;
1593+
}
1594+
RETURN_TRUE;
15871595
}
15881596
/* }}} */
15891597
#endif
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
Error in multi query
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once __DIR__ . '/connect.inc';
12+
13+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
14+
15+
$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);
16+
17+
$mysqli->multi_query("SELECT 1; SELECT 2; Syntax Error");
18+
19+
try {
20+
do {
21+
if ($res = $mysqli->store_result()) {
22+
var_dump($res->fetch_all(MYSQLI_ASSOC));
23+
$res->free();
24+
}
25+
} while ($mysqli->more_results() && $mysqli->next_result());
26+
} catch (mysqli_sql_exception $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
30+
$mysqli->query("DROP PROCEDURE IF EXISTS p");
31+
$mysqli->query('CREATE PROCEDURE p() READS SQL DATA BEGIN SELECT 1; SELECT foobar FROM table_that_does_not_exist; END;');
32+
33+
$stmt = $mysqli->prepare("CALL p()");
34+
$stmt->execute();
35+
36+
try {
37+
do {
38+
$stmt->bind_result($num);
39+
while ($stmt->fetch()) {
40+
echo "num = $num\n";
41+
}
42+
} while ($stmt->more_results() && $stmt->next_result());
43+
} catch (mysqli_sql_exception $e) {
44+
echo $e->getMessage(), "\n";
45+
}
46+
47+
$mysqli->query("DROP PROCEDURE IF EXISTS p");
48+
49+
?>
50+
--EXPECTF--
51+
array(1) {
52+
[0]=>
53+
array(1) {
54+
[1]=>
55+
string(1) "1"
56+
}
57+
}
58+
array(1) {
59+
[0]=>
60+
array(1) {
61+
[2]=>
62+
string(1) "2"
63+
}
64+
}
65+
You have an error in your SQL syntax; %s
66+
num = 1
67+
Table '%s.table_that_does_not_exist' doesn't exist

ext/mysqli/tests/mysqli_report.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,14 @@ Warning: mysqli_rollback(): (%s/%d): Commands out of sync; you can't run this co
330330

331331
Warning: mysqli_stmt_prepare(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
332332

333+
Warning: mysqli_next_result(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
334+
335+
Warning: mysqli_next_result(): (%s/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
336+
333337
Warning: mysqli_store_result(): (%s/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
334338

339+
Warning: mysqli_next_result(): (%s/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
340+
335341
Warning: mysqli_stmt_attr_set(): (%s/%d): Not implemented in %s on line %d
336342
mysqli_kill(): Argument #2 ($process_id) must be greater than 0
337343

0 commit comments

Comments
 (0)