PHP 4.0 Bug #6627: pg_fetch_array omits field names in case of NULL values
| From: | c_froehler at lycosmail dot com | Date: | Fri, 08 Sep 2000 13:11:05 +0000 |
| Subject: | PHP 4.0 Bug #6627: pg_fetch_array omits field names in case of NULL values | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-32656@lists.php.net to get a copy of this message | ||
From: c_froehler@lycosmail.com
Operating system: Linux 2.2.12
PHP version: 4.0.2
PHP Bug Type: PostgreSQL related
Bug description: pg_fetch_array omits field names in case of NULL values
After upgrading from PHP 4.0.1pl2 to 4.0.2 pg_fetch_array acts differently if the optional third
parameter is missing or is set as PGSQL_BOTH
Prior to the upgrade, it created the associative values (with field names) as well as values that
could be accessed by index numbers for all values.
But with 4.0.2, for fields that have a NULL value, the associative array entry is no longer
generated. This results in a PHP warning message when the entry is to be read (and breaks my
application).
This was reproducable on two machines, both PHP4.0.2, PostgreSQL 7.0.0, Linux 2.2.12
Example:
in PostgreSQL:
CREATE TABLE tblTest (fldInteger INT4, fldVarchar VARCHAR(20));
INSERT INTO tblTest (fldInteger, fldVarchar) VALUES (123, 'PHP rocks');
INSERT INTO tblTest (fldInteger, fldVarchar) VALUES (null, null);
PHP Script
<?php
// query example data
$db=pg_connect("dbname=mydb port=5432 user=pguser password=");
$result = pg_exec ( $db, "SELECT fldInteger, fldVarchar FROM tblTest;");
// loop through result set and show each field name and content
for ( $i=0; $i < pg_numrows($result) and
$resultrow = pg_fetch_array($result, $i, PGSQL_BOTH); $i++)
{
echo "Record #".$i."<br>";
foreach($resultrow as $key=>$val)
{ echo $key."=>".$val."<br>"; }
echo "<br>";
}
?>
The output of this script is the following, if the third param of pg_fetch_array is set to
PGSQL_BOTH or omitted:
Record #0
0=>123
fldinteger=>123
1=>PHP rocks
fldvarchar=>PHP rocks
Record #1
0=>
1=>
If the third param is PGSQL_ASSOC, this is the output:
Record #0
fldinteger=>123
fldvarchar=>PHP rocks
Record #1
fldinteger=>
fldvarchar=>
And here is my conficure line:
"./configure" \
"--with-pgsql" \
"--enable-trans-sid" \
"--disable-debug" \
"--enable-ftp" \
"--with-apxs=/www/bin/apxs" \
"--enable-track-vars" \
"$@"