#47710 [Com]: Undefined Index when accessing results by array
ID: 47710 Comment by: grant at coolhandjob dot com Reported By: grant at coolhandjob dot com Status: Feedback Bug Type: PDO related Operating System: CentOS 5.2 PHP Version: 5.3, 6CVS (2009-03-18) New Comment: It returns: Array ( [id] => 2 [0] => 2 [name] => cod [1] => cod ) Array ( [id] => 1 [0] => 1 [name] => mohaa [1] => mohaa ) I can access $row[0] etc just fine but not $row["id"] or $row["name"] as thats when I get undefined index error. Previous Comments: [2009-04-30 10:54:49] j...@php.net What does this script output: setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT id, name FROM games ORDER BY name'; foreach ($pdo->query($sql) as $row) { print_r($row); } } catch(PDOException $e) { echo $e->getMessage(); } ?> -------------------- [2009-03-18 20:41:49] grant at coolhandjob dot com 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: --- 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'] . ""; } 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 this bug report at http://bugs.php.net/?id=47710&edit=1
#47710 [NEW]: Undefined Index when accessing results by array
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: --- 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'] . ""; } 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