ID:               48015
 Updated by:       scott...@php.net
 Reported By:      blackmagic at computer dot org
 Status:           Bogus
 Bug Type:         PostgreSQL related
 Operating System: Centos 5.3
 PHP Version:      5.2.9
 New Comment:

The default value is PGSQL_BOTH so I can use

$result[0] OR $result['columnName']

That is the reason for this, if you don't want to then change the
parameter like you've done. The end.

It's been this way for several years and changing it would break
backwards compatibility.


Previous Comments:
------------------------------------------------------------------------

[2009-04-20 09:07:01] blackmagic at computer dot org

Why would the function return the data twice? What good is that to
anyone?

If you were to say 'it returns the data and the column headings in
default mode' I would say 'that's useful'. However that's not what the
function is doing in default mode. It is returning the data twice, which
is of no use to anyone.

------------------------------------------------------------------------

[2009-04-20 08:18:24] j...@php.net

Like already said above: By default the function returns all fields
twice. Once with numeric index and once with the field name as the
index.

------------------------------------------------------------------------

[2009-04-20 04:53:08] blackmagic at computer dot org

Changing pg_fetch_array() to:
$details = pg_fetch_array($db_result, $index, PGSQL_NUM);   
produces correct results with the implode() and foreach() methods. But
it doesn't explain the behaviour I've been experiencing before including
the PGSQL_NUM parameter in the parameter list.

Clearly I was getting a result that wasn't the intended result, ie,
instead of getting values and column names I was getting repeated
values.

------------------------------------------------------------------------

[2009-04-20 04:22:12] blackmagic at computer dot org

I understand that the array contains the column names and the
corresponding key values.

The problem is I'm not getting back the column names and the key
values, I'm getting the key values twice.

I thought I would try something else:
foreach($details as $value) $result .= ($value . '|'); 
instead of $company[$index] = implode('|', $details);

The results are the same for the implode() method and the foreach()
method: The key values are doubled up in the result the script sends
back to the browser.

I've captured the result with a window.alert, but can't paste it into
this reply. I'm sending it to you as a separate e-mail with an Word
attachment.

Thanks for your assistance.

MJR

------------------------------------------------------------------------

[2009-04-20 01:39:12] scott...@php.net

Jani was trying to get you see to that pg_fetch_array has two entries
because it has both the numeric keys AND the column name.

It's quite clearly in the manual that this is the default behavior of
pg_fetch_array. There is a third parameter you can add to only return
numeric keys and therefore resulting in one set when you implode.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/48015

-- 
Edit this bug report at http://bugs.php.net/?id=48015&edit=1

Reply via email to