[php-src] PR #25514: [WIP] Enable selecting a group by column name in PDO::FETCH_GROUP
| From: | 7snovic | Date: | Tue, 17 Nov 2026 09:49:29 +0000 |
| Subject: | [php-src] PR #25514: [WIP] Enable selecting a group by column name in PDO::FETCH_GROUP | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40720@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25514
Author: 7snovic
TL;DR
I'm not sure yet if this change requires a new dedicated RFC. So, please let me know if this is
required to start the discussion internally.
----
#### The context
By default, using PDO::FETCH_GROUP will pick the first selected column from the row and pops it out
from the result object/array.
So, running something like:
```
SELECT country, id, name from users
```
This will output a list of rows grouped by country.
The pain with this, is that you must define the whole columns list and put your required group_key
at the first of this list.
### The proposal
Allowing adding a new parameter to be used as a grouping_key
```
$row = $stmt->fetchAll(\PDO::FETCH_GROUP, 'country');
```
### BC
This won't affect the current behaviour, the second argument is optional, so doing this:
```
$row = $stmt->fetchAll(\PDO::FETCH_GROUP);
```
Should work using the current behaviour.
-----
Again, I'm just confused if I should go start a new internal discussion or this can discussed
here. So I can add the missed test cases and add some documentation describing the new added
argument.