From: steven at pearavenue dot com
Operating system: Redhat 9.0/Apache 2.0
PHP version: 4.3.4
PHP Bug Type: PostgreSQL related
Bug description: pg_fetch_object returns NULL on serial and INT in record but returns
strings NP
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 bug report at http://bugs.php.net/?id=26132&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26132&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26132&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26132&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26132&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26132&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=26132&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26132&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26132&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26132&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26132&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26132&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26132&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26132&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26132&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26132&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26132&r=float