summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-11-11 16:03:10 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-11-11 16:03:10 +0100
commitd776c31a3404ade29dacd3487b99adefdcec09a2 (patch)
tree125ce9f6e91ef2cfb886f622f82d7d3c0083d8dd
parent2d2d42b2681b97de654b02c0edbac87dc94e0ce5 (diff)
parenteda749260448c2cfbc628592c0943263d03d7119 (diff)
downloadphp-git-d776c31a3404ade29dacd3487b99adefdcec09a2.tar.gz
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Handle errors during next_result()
-rw-r--r--ext/mysqli/mysqli_api.c12
-rw-r--r--ext/mysqli/tests/mysqli_next_result_error.phpt67
-rw-r--r--ext/mysqli/tests/mysqli_report.phpt6
3 files changed, 83 insertions, 2 deletions
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index af12137885..d1e0634dc7 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1552,7 +1552,11 @@ PHP_FUNCTION(mysqli_next_result) {
}
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
- RETURN_BOOL(!mysql_next_result(mysql->mysql));
+ if (mysql_next_result(mysql->mysql)) {
+ MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
}
/* }}} */
@@ -1583,7 +1587,11 @@ PHP_FUNCTION(mysqli_stmt_next_result) {
}
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
- RETURN_BOOL(!mysql_stmt_next_result(stmt->stmt));
+ if (mysql_stmt_next_result(stmt->stmt)) {
+ MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
}
/* }}} */
#endif
diff --git a/ext/mysqli/tests/mysqli_next_result_error.phpt b/ext/mysqli/tests/mysqli_next_result_error.phpt
new file mode 100644
index 0000000000..4118bd0eab
--- /dev/null
+++ b/ext/mysqli/tests/mysqli_next_result_error.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Error in multi query
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+
+require_once __DIR__ . '/connect.inc';
+
+mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
+
+$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);
+
+$mysqli->multi_query("SELECT 1; SELECT 2; Syntax Error");
+
+try {
+ do {
+ if ($res = $mysqli->store_result()) {
+ var_dump($res->fetch_all(MYSQLI_ASSOC));
+ $res->free();
+ }
+ } while ($mysqli->more_results() && $mysqli->next_result());
+} catch (mysqli_sql_exception $e) {
+ echo $e->getMessage(), "\n";
+}
+
+$mysqli->query("DROP PROCEDURE IF EXISTS p");
+$mysqli->query('CREATE PROCEDURE p() READS SQL DATA BEGIN SELECT 1; SELECT foobar FROM table_that_does_not_exist; END;');
+
+$stmt = $mysqli->prepare("CALL p()");
+$stmt->execute();
+
+try {
+ do {
+ $stmt->bind_result($num);
+ while ($stmt->fetch()) {
+ echo "num = $num\n";
+ }
+ } while ($stmt->more_results() && $stmt->next_result());
+} catch (mysqli_sql_exception $e) {
+ echo $e->getMessage(), "\n";
+}
+
+$mysqli->query("DROP PROCEDURE IF EXISTS p");
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(1) {
+ [1]=>
+ string(1) "1"
+ }
+}
+array(1) {
+ [0]=>
+ array(1) {
+ [2]=>
+ string(1) "2"
+ }
+}
+You have an error in your SQL syntax; %s
+num = 1
+Table '%s.table_that_does_not_exist' doesn't exist
diff --git a/ext/mysqli/tests/mysqli_report.phpt b/ext/mysqli/tests/mysqli_report.phpt
index 1dbf1e4dc1..840c2c017a 100644
--- a/ext/mysqli/tests/mysqli_report.phpt
+++ b/ext/mysqli/tests/mysqli_report.phpt
@@ -330,8 +330,14 @@ Warning: mysqli_rollback(): (%s/%d): Commands out of sync; you can't run this co
Warning: mysqli_stmt_prepare(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
+Warning: mysqli_next_result(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
+
+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
+
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
+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
+
Warning: mysqli_stmt_attr_set(): (%s/%d): Not implemented in %s on line %d
mysqli_kill(): Argument #2 ($process_id) must be greater than 0