Req #48721 [Asn->Wfx]: Added parameter to pg_fetch_all allowing index to be column based
Edit report at https://bugs.php.net/bug.php?id=48721&edit=1
ID: 48721
Updated by: yohgaki@php.net
Reported by: eric dot schultz at cyvon dot com
Summary: Added parameter to pg_fetch_all allowing index to be
column based
-Status: Assigned
+Status: Wont fix
Type: Feature/Change Request
Package: PostgreSQL related
Operating System: Linux
PHP Version: 5.2.10
Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
I forgot about compound keys. Therefore, it's simply cannot be done.
You can convert it with one line.
<?php
$res = array(array('id'=>1, 'a'=>'abc'),
array('id'=>2, 'a'=>'xyz'));
array_walk($res, function($e, $k) use (&$new) {$new[$e['id']] = $e;});
var_dump($new);
Previous Comments:
------------------------------------------------------------------------
[2012-03-31 06:01:03] yohgaki@php.net
I think I marked the same request as "wont't fix".
This sounds reasonable.
------------------------------------------------------------------------
[2009-06-29 15:31:25] eric dot schultz at cyvon dot com
Description:
------------
I would love if the pg_fetch_all could take a parameter that would (optionally) allow the indexing
of the resultset to be a column value as opposed to 0-based. (as many tables include a primary
key/id)
Reproduce code:
---------------
---
From manual page: function.pg-fetch-all
---
I find myself doing the following VERY often:
$res = pg_query("Select * from set_options");
if(!$res) return(0);
$ret = array();
while($r = pg_fetch_assoc($res)){
$ret[$r['id']] = $r; }
return($ret);
Expected result:
----------------
above produces an associative array indexed on the "id" column. Would like this built into
the pg_fetch_all
Actual result:
--------------
see above
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48721&edit=1
Thread (3 messages)