From: grant at coolhandjob dot com Operating system: CentOS 5.2 PHP version: 6CVS-2009-03-18 (snap) PHP Bug Type: PDO related Bug description: Undefined Index when accessing results by array
Description: ------------ When trying to access the returned associative array I get a undefined index error. Works as expected in PHP5.2.9 but have the same error with the latest PHP5.3. Reproduce code: --------------- <?php try { $pdo = new PDO("mysql:host=localhost;dbname=dbname;", "dbuser", "password"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT id, name FROM games ORDER BY name'; foreach ($pdo->query($sql) as $row) { print $row['id'] . " - "; print $row['name'] . "<br />"; } print_r($row); } catch(PDOException $e) { echo $e->getMessage(); } ?> Expected result: ---------------- 2 - cod 1 - mohaa Array ( [id] => 1 [0] => 1 [name] => mohaa [1] => mohaa ) Actual result: -------------- Notice: Undefined index: id in /var/www/html/temp.php on line 9 - Notice: Undefined index: name in /var/www/html/temp.php on line 10 Notice: Undefined index: id in /var/www/html/temp.php on line 9 - Notice: Undefined index: name in /var/www/html/temp.php on line 10 Array ( [id] => 1 [0] => 1 [name] => mohaa [1] => mohaa ) -- Edit bug report at http://bugs.php.net/?id=47710&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47710&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47710&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47710&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47710&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47710&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47710&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47710&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47710&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47710&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47710&r=support Expected behavior: http://bugs.php.net/fix.php?id=47710&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47710&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47710&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47710&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47710&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47710&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47710&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47710&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47710&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47710&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47710&r=mysqlcfg