summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-12-11 12:43:19 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-12-11 12:52:59 +0100
commitad8eb116d831035584e178bffb85d68c1ca3d7fa (patch)
tree07284aa065875a06c74279bd3b5d95ceb5b1233d /ext/pdo_mysql
parentd6b4b82a386402058c0eceaec31cfd7b5da765f8 (diff)
downloadphp-git-ad8eb116d831035584e178bffb85d68c1ca3d7fa.tar.gz
Fixed bug #67004
Repeated execute() with native PS failed to release the previous result set on libmysqlclient. Move freeing the result set into a common location.
Diffstat (limited to 'ext/pdo_mysql')
-rw-r--r--ext/pdo_mysql/mysql_statement.c7
-rw-r--r--ext/pdo_mysql/tests/bug67004.phpt34
2 files changed, 37 insertions, 4 deletions
diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c
index 80d8747cd9..9a9249d42f 100644
--- a/ext/pdo_mysql/mysql_statement.c
+++ b/ext/pdo_mysql/mysql_statement.c
@@ -303,7 +303,6 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_RETURN(0);
}
- pdo_mysql_free_result(S);
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
/* }}} */
@@ -316,14 +315,14 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_ENTER("pdo_mysql_stmt_execute");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
+ /* ensure that we free any previous unfetched results */
+ pdo_mysql_free_result(S);
S->done = 0;
+
if (S->stmt) {
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
}
- /* ensure that we free any previous unfetched results */
- pdo_mysql_free_result(S);
-
if (mysql_real_query(H->server, stmt->active_query_string, stmt->active_query_stringlen) != 0) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
diff --git a/ext/pdo_mysql/tests/bug67004.phpt b/ext/pdo_mysql/tests/bug67004.phpt
new file mode 100644
index 0000000000..98b0a08d0c
--- /dev/null
+++ b/ext/pdo_mysql/tests/bug67004.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #67004: Executing PDOStatement::fetch() more than once prevents releasing resultset
+--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');
+$dbh = MySQLPDOTest::factory();
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$stmt = $dbh->prepare("SELECT ?");
+
+$stmt->execute(["foo"]);
+var_dump($stmt->fetchColumn(0));
+
+$stmt->execute(["bar"]);
+var_dump($stmt->fetchColumn(0));
+
+$stmt = $dbh->prepare("SELECT ?");
+$stmt->execute(["baz"]);
+var_dump($stmt->fetchColumn(0));
+
+?>
+--EXPECT--
+string(3) "foo"
+string(3) "bar"
+string(3) "baz"