note 15354 added to function.pg-fetch-object

From: Date: Thu, 06 Sep 2001 15:50:12 +0000
Subject: note 15354 added to function.pg-fetch-object
Groups: php.notes 
Request: Send a blank email to php-notes+get-17729@lists.php.net to get a copy of this message
The optional result_type argument to the pg_fetch_object() method is listed as requiring one of the three values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. This does not work if these values are used. Instead, use one of these: "1" for result_type PGSQL_ASSOC, "2" for result_type PGSQL_NUM, "3" for result_type PGSQL_BOTH. It appears to default to "3" in php version 4.0.4pl1(don't know about other versions), which returns the contents of each field indexed by both an integer, and the column name. <b>Code ex: </b> $conn = pg_connect("host=localhost"); $query="select * from foo;"; $ret=pg_exec($conn, $query); $row=0; $data=pg_fetch_object($ret,$row,"1"); foreach($data as $key => $value){ echo "$key = $value"; #prints $key as associative value; i.e. column name. } $data=pg_fetch_object($ret,$row,"2"); foreach($data as $key => $value){ echo "$key = $value"; #prints $key as numeric value only i.e. first field of table foo named fname is keyed here as '0' } $data=pg_fetch_object($ret,$row,"3"); foreach($data as $key => $value){ echo "$key = $value"; #prints $key as both numeric and associative, listing data referenced by $key twice each. } http://www.php.net/manual/en/function.pg-fetch-object.php

« previous php.notes (#17729) next »