[php-src] Issue #21683: pdo_pgsql crashes with ATTR_PREFETCH=0 on empty result set

[email protected] (thomasschiet)
Newsgroups php.bugs
Message-ID <zOiQUTLqygf454mpFti6ffxtNvHO9D5F7ffAWnXeWLc@main.internal.php.net>
Issue: https://github.com/php/php-src/issues/21683
Author: thomasschiet

### Description

The following code:

```php
<?php
$pdo = new PDO('pgsql:...');
$pdo->setAttribute(PDO::ATTR_PREFETCH, 0);

$pdo->exec("CREATE TEMP TABLE empty_t (id int, val text)");

$stmt = $pdo->query("SELECT * FROM empty_t");
var_dump($stmt->fetch());
```

Resulted in this output:
```
PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000]: General error: 7  in Command line code:9
```

But I expected this output instead:
```
bool(false)
```


### PHP Version

```plain
PHP 8.5.4 (cli) (built: Mar 10 2026 23:15:23) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.5.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies
```

### Operating System

_No response_
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.