[php-src] Issue #25106: PDO SQLite returns a phantom null row when an unread statement is re-executed with no results
| From: | JoaoMarcos44 | Date: | Sat, 31 Oct 2026 18:37:54 +0000 |
| Subject: | [php-src] Issue #25106: PDO SQLite returns a phantom null row when an unread statement is re-executed with no results | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253959@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25106
Author: JoaoMarcos44
### Description
> AI-assisted report. The explanation was prepared with AI assistance. The reproduction and
> outputs below were verified by local execution.
> Reusing a successful prepared SELECT without consuming its first result can make the next empty
> result contain a row of null values. Explicitly calling
>
closeCursor() before the second execution also reproduces the
> problem.
```php
<?php
$db = new PDO('sqlite::memory:');
$stmt = $db->prepare('SELECT 42 AS answer WHERE ?');
$stmt->execute([1]);
$stmt->execute([0]);
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)), "\n";
```
> Actual output:
```text
[{"answer":null}]
```
> Expected output:
```text
[]
```
> Consuming the first result before re-execution produces the expected empty array. This can
> fabricate records and incorrect result counts in applications that reuse prepared statements. The
> driver retains its prefetched-row flag when resetting the cursor.
### PHP Version
```text
PHP 8.5.12 (cli) (built: Oct 28 2026 01:23:38) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
```
> Also reproduced on PHP 8.7.0-dev at commit
> 248c5c45409667b5e69bba38a92c5cc9edd7582a.
### Operating System
Debian GNU/Linux 12 (bookworm), Linux container.