Skip to content

Commit 8d8029e

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: Fix GH-24372: Keep stmt->executed set across PDOStatement::execute()
2 parents 08fecf6 + 73d2da7 commit 8d8029e

2 files changed

Lines changed: 7 additions & 27 deletions

File tree

‎ext/pdo/pdo_stmt.c‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -380,29 +380,6 @@ static bool really_register_bound_param(struct pdo_bound_param_data *param, pdo_
380380
}
381381
/* }}} */
382382

383-
static bool pdo_stmt_do_next_rowset(pdo_stmt_t *stmt);
384-
385-
static void pdo_stmt_invalidate_result(pdo_stmt_t *stmt)
386-
{
387-
if (stmt->methods->cursor_closer) {
388-
stmt->methods->cursor_closer(stmt);
389-
} else {
390-
do {
391-
while (stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0))
392-
;
393-
if (!stmt->methods->next_rowset) {
394-
break;
395-
}
396-
397-
if (!pdo_stmt_do_next_rowset(stmt)) {
398-
break;
399-
}
400-
} while (1);
401-
}
402-
403-
stmt->executed = 0;
404-
}
405-
406383
/* {{{ Execute a prepared statement, optionally binding parameters */
407384
PHP_METHOD(PDOStatement, execute)
408385
{
@@ -419,9 +396,10 @@ PHP_METHOD(PDOStatement, execute)
419396
RETURN_THROWS();
420397
}
421398

422-
if (stmt->executed) {
423-
pdo_stmt_invalidate_result(stmt);
399+
if (stmt->executed && stmt->methods->cursor_closer) {
400+
stmt->methods->cursor_closer(stmt);
424401
}
402+
stmt->execute_incomplete = 1;
425403
PDO_STMT_CLEAR_ERR();
426404

427405
if (input_params) {
@@ -488,6 +466,7 @@ PHP_METHOD(PDOStatement, execute)
488466
RETURN_FALSE;
489467
}
490468
if (stmt->methods->executer(stmt)) {
469+
stmt->execute_incomplete = 0;
491470
if (!stmt->executed) {
492471
/* this is the first execute */
493472

@@ -594,7 +573,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, enum pdo
594573

595574
static bool do_fetch_common(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori, zend_long offset) /* {{{ */
596575
{
597-
if (!stmt->executed) {
576+
if (!stmt->executed || stmt->execute_incomplete) {
598577
return false;
599578
}
600579

‎ext/pdo/php_pdo_driver.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ struct _pdo_stmt_t {
574574
* emulate prepare and bind on its behalf */
575575
uint16_t supports_placeholders:2;
576576
uint16_t in_param_event:1;
577-
uint16_t reserved: 11;
577+
uint16_t execute_incomplete:1;
578+
uint16_t reserved: 10;
578579

579580
/* keep track of bound input parameters. Some drivers support
580581
* input/output parameters, but you can't rely on that working */

0 commit comments

Comments
 (0)