PHP 4.0 Bug #6627 Updated: pg_fetch_array omits field names in case of NULL values
| From: | Bug Database | Date: | Sun, 10 Sep 2000 14:06:48 +0000 |
| Subject: | PHP 4.0 Bug #6627 Updated: pg_fetch_array omits field names in case of NULL values | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-32820@lists.php.net to get a copy of this message | ||
ID: 6627
Updated by: jah
Reported By: c_froehler@lycosmail.com
Status: Closed
Bug Type: PostgreSQL related
Assigned To:
Comments:
Fixed in current CVS. Fetch the latest version of ext/pgsql/pgsql.c from
http://cvs.php.net/viewcvs.cgi/~checkout~/php4/ext/pgsql/pgsql.c?rev=1.68
and recompile.
As as side note, this mistake happened when fixing/changing the returned value of
NULL columns. In your example, you could now test if ($val === NULL).
Previous Comments:
---------------------------------------------------------------------------
[2000-09-08 09:11:05] c_froehler@lycosmail.com
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"
"$@"
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6627