Commit 96f29013e0c for php.net

commit 96f29013e0c82ef239267869250eef4b55c6519a
Author: Saki Takamachi <saki@sakiot.com>
Date:   Fri Apr 24 21:01:24 2026 +0900

    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

diff --git a/NEWS b/NEWS
index 13b3286c7b6..1e917d3f01c 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 4e41ea40f08..51c2f58c6c2 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;
 }