[php-src] master: Fixed the behavior when using FETCH_DEFAULT (#21864)
| From: | Saki Takamachi | Date: | Sat, 05 Sep 2026 01:22:21 +0000 |
| Subject: | [php-src] master: Fixed the behavior when using FETCH_DEFAULT (#21864) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141070@lists.php.net to get a copy of this message | ||
Author: Saki Takamachi (SakiTakamachi)
Date: 2026-09-05T10:20:10+09:00
Commit: https://github.com/php/php-src/commit/96f29013e0c82ef239267869250eef4b55c6519a
Raw diff: https://github.com/php/php-src/commit/96f29013e0c82ef239267869250eef4b55c6519a.diff
Fixed the behavior when using FETCH_DEFAULT (#21864)
When using FETCH_DEFAULT, instead of setting the mode to a default value,
it was modified so that the default value is not overridden.
Closes #21864
Changed paths:
M NEWS
M ext/pdo/pdo_stmt.c
Diff:
diff --git a/NEWS b/NEWS
index 13b3286c7b67..1e917d3f01c9 100644
--- a/NEWS
+++ b/NEWS
@@ -76,6 +76,10 @@ PHP NEWS
. Fixed bug GH-23444 (ODBC_ATTR_ASSUME_UTF8 corrupts Unicode data outside
Windows). (Calvin Buckley, Lazizbek Ergashev)
+- PDO Sqlite:
+ . Fixed bug GH-20214 (PDO::FETCH_DEFAULT unexpected behavior with
+ PDOStatement::setFetchMode). (SakiTakamachi)
+
- Phar:
. Fixed bug GH-23418 (Use-after-free when looking up mounted directories).
(Weilin Du)
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 4e41ea40f08b..51c2f58c6c2a 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -1729,7 +1729,7 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t
mode_a
;
}
- stmt->default_fetch_type = PDO_FETCH_BOTH;
+ stmt->default_fetch_type = stmt->dbh->default_fetch_type;
flags = mode & PDO_FETCH_FLAGS;
@@ -1737,6 +1737,8 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t
mode_a
return false;
}
+ bool use_default = (mode & ~PDO_FETCH_FLAGS) == PDO_FETCH_USE_DEFAULT;
+
switch (mode & ~PDO_FETCH_FLAGS) {
case PDO_FETCH_USE_DEFAULT:
case PDO_FETCH_LAZY:
@@ -1858,7 +1860,9 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t
mode_a
return false;
}
- stmt->default_fetch_type = mode;
+ if (!use_default) {
+ stmt->default_fetch_type = mode;
+ }
return true;
}