|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26132 pg_fetch_object returns NULL on serial and INT in record but returns strings NP
Submitted: 2003-11-05 03:11 UTC Modified: 2003-11-06 03:45 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: steven at pearavenue dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.3.4 OS: Redhat 9.0/Apache 2.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: steven at pearavenue dot com
New email:
PHP Version: OS:


 [2003-11-05 03:11 UTC] steven at pearavenue dot com
I checked on PHP 5.0beta too and the same problem there.  pg_fetch_object returns serial or integers as NULL while but returns varchars in the same record as string - pg_fetch_array returns the entire data correctly.  Similar code worked fine on another server using MySQl Support.

You need a table like this:
CREATE TABLE public.feeds
  feedid serial NOT NULL,
  uri varchar(255) NOT NULL DEFAULT '',
  category int4 NOT NULL DEFAULT 0,

  CONSTRAINT feeds_pkey PRIMARY KEY (feedid),
  CONSTRAINT feeds_uri_key UNIQUE (uri)

Reproduce code:
$pgConnectStr = "... your connect string";
$link = pg_connect( $pgConnectStr ) or die( "Could not connect" );

$stat = pg_connection_status($link);
if($stat == PGSQL_CONNECTION_OK ) {
  echo "connection_status: OK<br />";
} else {
  // report connection error                                                                                                        
  echo "connection_status: BAD<br />";
  echo( pg_last_error($link) );

$feedb = pg_query( $link, $sql);
echo( "<br />".pg_num_rows( $feedb )." Number of rows returned.<br />" );
// for each row in the table stuff the coresponding variables with the data:                                                        
echo ( "ARRAY<br />" );                                                                                                             
while( $fields = pg_fetch_array( $feedb ) ){                                                                                        
  echo ( "<br />Feed[0]: $fields[0]<br />" );                                                                                       
  echo ( "<br />Feed[1]: {$fields[1]}<br />" );                                                                                     
  echo ( "<br />Feed[2]: {$fields[2]}<br />" );                                                                                     
echo ( "OBJECT<br />" );

while( $row = pg_fetch_object( $feedb ) ){

  if( $row->FeedID == NULL) {
    $id = "NULL";
  } else {
    $id = $row->FeedID;
  echo ( "<br />FeedID:".$id."<br />" );

  $uri = $row->uri;
  echo ( "<br />uri: $uri<br />" );

  if( $row->category == NULL) {
    $c = "NULL";
  } else {
    $c = $row->category;
  echo ( "<br />category: $c<br />" );


Expected result:
We expect the serial and integer values to appear in the result from pg_fetch_object

Actual result:
You will note that the output produces NULLs instead.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-05 03:14 UTC] steven at pearavenue dot com
You will want this SQL :

$sql = "SELECT  FeedID, uri                                                                                                         
        FROM    feeds     ";
 [2003-11-05 03:19 UTC] steven at pearavenue dot com
Oh, and of course, you need to comment out either the ARRAY code or the OBJECT code when you test this. :) Try each in turn.
 [2003-11-05 18:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Pgsql always lower cases field names, which is why $row->FeedID returns NULL. You should use $row->feedid instead.
 [2003-11-06 03:45 UTC] steven at pearavenue dot com
Ok. The behavior is intentional, but incorrect. 

Please consider that the object constructor should mirror the behavior/semantics of postgres and thus treat method names similarly.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 02:01:28 2024 UTC