Skip to content

Commit 220c1e2

Browse files
committed
Add a fix for PDO::ATTR_STRINGIFY_FETCHES=false with PHP < 8.1
1 parent 5c1b7b7 commit 220c1e2

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

wp-includes/sqlite-ast/class-wp-pdo-synthetic-statement.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ public function fetch(
239239
* Without it, these parameters have no effect.
240240
*/
241241

242+
/**
243+
* With PHP < 8.1, the "PDO::ATTR_STRINGIFY_FETCHES" value of "false"
244+
* is not working correctly with the PDO SQLite driver. In such case,
245+
* we need to manually convert the row values to the correct types.
246+
*/
247+
if ( PHP_VERSION_ID < 80100 && ! $this->getAttribute( PDO::ATTR_STRINGIFY_FETCHES ) ) {
248+
foreach ( $row as $i => $value ) {
249+
$type = $this->columns[ $i ]['native_type'];
250+
if ( 'integer' === $type ) {
251+
$row[ $i ] = (int) $value;
252+
} elseif ( 'float' === $type ) {
253+
$row[ $i ] = (float) $value;
254+
}
255+
}
256+
}
257+
242258
switch ( $mode ) {
243259
case PDO::FETCH_BOTH:
244260
$values = array();

0 commit comments

Comments
 (0)