From: contact at joycebabu dot com Operating system: PHP version: Irrelevant Package: PDO related Bug Type: Bug Bug description:FETCH_GROUP Does not work with FETCH_KEY_PAIR
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' ) -- Edit bug report at https://bugs.php.net/bug.php?id=63813&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63813&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63813&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63813&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63813&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63813&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63813&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63813&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63813&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63813&r=support Expected behavior: https://bugs.php.net/fix.php?id=63813&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63813&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63813&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63813&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63813&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63813&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63813&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63813&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63813&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63813&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63813&r=mysqlcfg