Skip to content

Commit

Permalink
PDO MySQL: Handle error during closeCursor()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Dec 9, 2020
1 parent 71b5f14 commit 23193e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/pdo_mysql/mysql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,8 @@ static int pdo_mysql_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */
while (mysql_more_results(S->H->server)) {
MYSQL_RES *res;
if (mysql_next_result(S->H->server) != 0) {
break;
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
res = mysql_store_result(S->H->server);
if (res) {
Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_mysql/tests/pdo_mysql_closecursor_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Error during closeCursor() of multi query
--SKIPIF--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();

$stmt = $db->query('SELECT 1; SELECT x FROM does_not_exist');
var_dump($stmt->fetchAll());
var_dump($stmt->closeCursor());
?>
--EXPECTF--
array(1) {
[0]=>
array(2) {
[1]=>
string(1) "1"
[0]=>
string(1) "1"
}
}

Warning: PDOStatement::closeCursor(): SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.does_not_exist' doesn't exist in %s on line %d
bool(false)

0 comments on commit 23193e8

Please sign in to comment.