php.net |  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
Votes:2
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: steven at pearavenue dot com
New email:
PHP Version: OS:

 

 [2003-11-05 03:11 UTC] steven at pearavenue dot com
Description:
------------
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)
) WITH OIDS;



Reproduce code:
---------------
<?php
$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.

Patches

Pull Requests

History

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] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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: Thu Dec 26 14:01:30 2024 UTC