From: christoph at ziegenberg dot de Operating system: Windows XP SP2 PHP version: 5.2.0 PHP Bug Type: PDO related Bug description: Wrong fieldnames in result (including table alias names)
Description: ------------ If you get the data of a query like "SELECT tablealias.fieldname FROM table tablealias.fieldname GROUP BY tablealias.fieldname" the result array contains not only the field name, but also the table alias name as field name. Only using "SELECT tablealias.fieldname AS fieldname..." fixes this problem, but this should not be neccessary. I don't know if this is a PDO or SQLite problem. Reproduce code: --------------- <?php $sldb = new PDO('sqlite:memory'); $sldb->query("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT)"); $sldb->query("INSERT INTO test (id) VALUES (1)"); $queries = array(); $queries[] = "SELECT id FROM test"; $queries[] = "SELECT t1.id FROM test t1"; $queries[] = "SELECT t1.id FROM test t1 GROUP BY t1.id"; $queries[] = "SELECT t1.id AS id FROM test t1 GROUP BY t1.id"; foreach ($queries as $query) { $stmt = $sldb->prepare($query); $stmt->execute(); if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo 'result for query "' . $query . '":<br />'; print_r($row); echo '<br /><br />'; } } ?> Expected result: ---------------- result for query "SELECT id FROM test": Array ( [id] => 1 ) result for query "SELECT t1.id FROM test t1": Array ( [id] => 1 ) result for query "SELECT t1.id FROM test t1 GROUP BY t1.id": Array ( [id] => 1 ) result for query "SELECT t1.id AS id FROM test t1 GROUP BY t1.id": Array ( [id] => 1 ) Actual result: -------------- result for query "SELECT id FROM test": Array ( [id] => 1 ) result for query "SELECT t1.id FROM test t1": Array ( [id] => 1 ) result for query "SELECT t1.id FROM test t1 GROUP BY t1.id": Array ( [t1.id] => 1 ) result for query "SELECT t1.id AS id FROM test t1 GROUP BY t1.id": Array ( [id] => 1 ) -- Edit bug report at http://bugs.php.net/?id=40064&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40064&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40064&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40064&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40064&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40064&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40064&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40064&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40064&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40064&r=support Expected behavior: http://bugs.php.net/fix.php?id=40064&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40064&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40064&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40064&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40064&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40064&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40064&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40064&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40064&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40064&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40064&r=mysqlcfg