note 93104 added to function.pg-fetch-array

From: Date: Sun, 23 Aug 2009 20:53:27 +0000
Subject: note 93104 added to function.pg-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-159816@lists.php.net to get a copy of this message
Note that when using PGSQL_BOTH, numerically and associatively indexed fields are separate variables and treated as such: <?php $res = pg_query("Select 'foo' as bar"); $data = pg_fetch_array($res, 0, PGSQL_BOTH); var_dump($data); // Array(2) // { // [0] => string(3) "foo" // ["bar"] => string(3) "foo" // } // This won't affect $data['bar'] $data[0] = 'bar'; var_dump($data); // Array(2) // { // [0] => string(3) "bar" // ["bar"] => string(3) "foo" // } ?> If you want to have reference binding between your numeric and associative indexes, you'll have to establish that yourself: <?php $result = pg_query("Select 'foo' as bar"); $data = pg_fetch_row($result); // Establish references between column name/number $from = $data; foreach($from as $cx => $value) { $key = pg_field_name($result, $cx); if (is_string($key)) $data[$key] =& $data[$cx]; } var_dump($data); // Array(2) // { // [0] => &string(3) "foo" // ["bar"] => &string(3) "foo" // } // Note the reference binding between $data[0] and $data['bar'] $data[0] = 'baz'; var_dump($data); // Array(2) // { // [0] => &string(3) "baz" // ["bar"] => &string(3) "baz" // } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 67.237.228.46 ---- Manual Page -- http://www.php.net/manual/en/function.pg-fetch-array.php Edit -- https://master.php.net/note/edit/93104 Del: integrated -- https://master.php.net/note/delete/93104/integrated Del: useless -- https://master.php.net/note/delete/93104/useless Del: bad code -- https://master.php.net/note/delete/93104/bad+code Del: spam -- https://master.php.net/note/delete/93104/spam Del: non-english -- https://master.php.net/note/delete/93104/non-english Del: in docs -- https://master.php.net/note/delete/93104/in+docs Del: other reasons-- https://master.php.net/note/delete/93104 Reject -- https://master.php.net/note/reject/93104 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159816) next »