|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2012-12-23 18:15 UTC] felipe@php.net
 
-Status: Open
+Status: Not a bug
  [2012-12-23 18:15 UTC] felipe@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 07:00:01 2025 UTC | 
Description: ------------ Documentation for PDO::FETCH_GROUP says "Group return by values. Usually combined with PDO::FETCH_COLUMN or PDO::FETCH_KEY_PAIR." But FETCH_GROUP does not work with FETCH_KEY_PAIR. When three columns are specified in the query, the fetch fails with the erorr message "Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: PDO::FETCH_KEY_PAIR fetch mode requires the result set to contain extactly 2 columns." When 2 columns are specified in the query, the fetch returns an associative array with only one value for each unique grouped key, which is useless. Test script: --------------- /* employee table -------------------------------- | location | emp_id | name | -------------------------------- | New York | 1 | John | | New York | 2 | Jane | | London | 3 | Jack | | London | 4 | Nick | -------------------------------- */ $db->query('SELECT location, emp_id, name FROM employees'); $employees = $db->fetchAll(PDO::FETCH_GROUP | PDO::FETCH_KEY_PAIR); Expected result: ---------------- array( 'New York' => array( 1 => 'John', 2 => 'Jane' ), 'London' => array( 3 => 'Jack', 4 => 'Nick' ) ) Actual result: -------------- array( 'New York' => 'Jane', 'London' => 'Nick' )