summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-12-08 11:30:54 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-12-08 11:30:54 +0100
commitbd093ad8615267ae4ff1a237e6285dc182a9ff57 (patch)
tree7f7fc6cb85c43b2b51c1575aa6201c9f70401543
parenta83cc03c138b8cf27a840bd7cd913eb7050e55ba (diff)
downloadphp-git-bd093ad8615267ae4ff1a237e6285dc182a9ff57.tar.gz
Fixed bug #63185
-rw-r--r--NEWS2
-rw-r--r--ext/pdo_mysql/mysql_statement.c1
-rw-r--r--ext/pdo_mysql/tests/bug63185.phpt67
3 files changed, 70 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index dab2198b9b..b242d30415 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ PHP NEWS
- PDO MySQL:
. Fixed bug #80458 (PDOStatement::fetchAll() throws for upsert queries).
(Kamil Tekiela)
+ . Fixed bug #63185 (nextRowset() ignores MySQL errors with native prepared
+ statements). (Nikita)
- Phpdbg:
. Fixed bug #76813 (Access violation near NULL on source operand). (cmb)
diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c
index 58711459ae..b2c37dcfec 100644
--- a/ext/pdo_mysql/mysql_statement.c
+++ b/ext/pdo_mysql/mysql_statement.c
@@ -357,6 +357,7 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_RETURN(0);
}
if (mysqlnd_stmt_next_result(S->stmt)) {
+ pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
diff --git a/ext/pdo_mysql/tests/bug63185.phpt b/ext/pdo_mysql/tests/bug63185.phpt
new file mode 100644
index 0000000000..4bf6d7e4db
--- /dev/null
+++ b/ext/pdo_mysql/tests/bug63185.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Bug #63185: nextRowset() ignores MySQL errors with native prepared statements
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
+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');
+
+$pdo = MySQLPDOTest::factory();
+$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$pdo->exec('DROP PROCEDURE IF EXISTS test_procedure_error_at_second');
+$pdo->exec('CREATE PROCEDURE test_procedure_error_at_second ()
+ BEGIN
+ SELECT "x" as foo;
+ SELECT * FROM no_such_table;
+ END');
+
+$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+$st = $pdo->query('CALL test_procedure_error_at_second()');
+var_dump($st->fetchAll());
+try {
+ var_dump($st->nextRowset());
+} catch (PDOException $e) {
+ echo $e->getMessage(), "\n";
+}
+unset($st);
+
+$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+$st = $pdo->query('CALL test_procedure_error_at_second()');
+var_dump($st->fetchAll());
+try {
+ var_dump($st->nextRowset());
+} catch (PDOException $e) {
+ echo $e->getMessage(), "\n";
+}
+var_dump($st->fetchAll());
+
+?>
+--EXPECTF--
+array(1) {
+ [0]=>
+ array(2) {
+ ["foo"]=>
+ string(1) "x"
+ [0]=>
+ string(1) "x"
+ }
+}
+SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.no_such_table' doesn't exist
+array(1) {
+ [0]=>
+ array(2) {
+ ["foo"]=>
+ string(1) "x"
+ [0]=>
+ string(1) "x"
+ }
+}
+SQLSTATE[42S02]: Base table or view not found: 1146 Table '%s.no_such_table' doesn't exist
+array(0) {
+}