Skip to content

Commit ad8eb11

Browse files
committed
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.
1 parent d6b4b82 commit ad8eb11

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ PHP NEWS
5757
. Fixed bug #72368 (PdoStatement->execute() fails but does not throw an
5858
exception). (Nikita)
5959
. Fixed bug #62889 (LOAD DATA INFILE broken). (Nikita)
60+
. Fixed bug #67004 (Executing PDOStatement::fetch() more than once prevents
61+
releasing resultset). (Nikita)
6062

6163
- Phar:
6264
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)

ext/pdo_mysql/mysql_statement.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
303303
PDO_DBG_RETURN(0);
304304
}
305305

306-
pdo_mysql_free_result(S);
307306
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
308307
}
309308
/* }}} */
@@ -316,14 +315,14 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
316315
PDO_DBG_ENTER("pdo_mysql_stmt_execute");
317316
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
318317

318+
/* ensure that we free any previous unfetched results */
319+
pdo_mysql_free_result(S);
319320
S->done = 0;
321+
320322
if (S->stmt) {
321323
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
322324
}
323325

324-
/* ensure that we free any previous unfetched results */
325-
pdo_mysql_free_result(S);
326-
327326
if (mysql_real_query(H->server, stmt->active_query_string, stmt->active_query_stringlen) != 0) {
328327
pdo_mysql_error_stmt(stmt);
329328
PDO_DBG_RETURN(0);

ext/pdo_mysql/tests/bug67004.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #67004: Executing PDOStatement::fetch() more than once prevents releasing resultset
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
$dbh = MySQLPDOTest::factory();
14+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
15+
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
16+
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
17+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
18+
$stmt = $dbh->prepare("SELECT ?");
19+
20+
$stmt->execute(["foo"]);
21+
var_dump($stmt->fetchColumn(0));
22+
23+
$stmt->execute(["bar"]);
24+
var_dump($stmt->fetchColumn(0));
25+
26+
$stmt = $dbh->prepare("SELECT ?");
27+
$stmt->execute(["baz"]);
28+
var_dump($stmt->fetchColumn(0));
29+
30+
?>
31+
--EXPECT--
32+
string(3) "foo"
33+
string(3) "bar"
34+
string(3) "baz"

0 commit comments

Comments
 (0)