ID: 26132 User updated by: steven at pearavenue dot com Reported By: steven at pearavenue dot com Status: Open Bug Type: PostgreSQL related Operating System: Redhat 9.0/Apache 2.0 PHP Version: 4.3.4 New Comment:
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. Previous Comments: ------------------------------------------------------------------------ [2003-11-05 03:14:07] steven at pearavenue dot com You will want this SQL : $sql = "SELECT FeedID, uri FROM feeds "; ------------------------------------------------------------------------ [2003-11-05 03:11:40] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26132&edit=1