|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-09-10 10:06 UTC] jah@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
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" \ "$@"