mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Handle errors during next_result()
This commit is contained in:
parent
c1f8dd4a33
commit
eda7492604
3 changed files with 83 additions and 2 deletions
|
@ -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
|
||||
|
|
67
ext/mysqli/tests/mysqli_next_result_error.phpt
Normal file
67
ext/mysqli/tests/mysqli_next_result_error.phpt
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue