com php-src: Handle errors during next_result(): ext/ mysqli/mysqli_api.c ext/mysqli/tests/mysqli_next_resu lt_error.phpt
ext/mysqli/tests/mysqli_report.phpt
| From: | Nikita Popov | Date: | Wed, 11 Nov 2020 15:02:52 +0000 |
| Subject: | com php-src: Handle errors during next_result(): ext/ mysqli/mysqli_api.c ext/mysqli/tests/mysqli_next_resu lt_error.phpt ext/mysqli/tests/mysqli_report.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114134@lists.php.net to get a copy of this message | ||
Commit: eda749260448c2cfbc628592c0943263d03d7119
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 11 Nov 2020 15:56:05 +0100
Parents: c1f8dd4a33f401fb1e0b4854b3162e3d7be3726d
Branches: PHP-7.4 PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eda749260448c2cfbc628592c0943263d03d7119
Log:
Handle errors during next_result()
Changed paths:
M ext/mysqli/mysqli_api.c
A ext/mysqli/tests/mysqli_next_result_error.phpt
M ext/mysqli/tests/mysqli_report.phpt
Diff:
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c
index 9a54171b307..9896ab8eda2 100644
--- a/ext/mysqli/mysqli_api.c
+++ b/ext/mysqli/mysqli_api.c
@@ -1608,7 +1608,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;
}
/* }}} */
@@ -1640,7 +1644,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 00000000000..4118bd0eab0
--- /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 33730976976..7a343bdef8f 100644
--- a/ext/mysqli/tests/mysqli_report.phpt
+++ b/ext/mysqli/tests/mysqli_report.phpt
@@ -331,8 +331,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
Warning: mysqli_kill(): processid should have positive value in %s on line %d