note 15354 deleted from function.pg-fetch-object by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 18:06:05 +0000 |
| Subject: | note 15354 deleted from function.pg-fetch-object by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24292@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.
}