From bd9f1e1d38108002fed31fbc5ef64e0693e2dc80 Mon Sep 17 00:00:00 2001 From: Kenneth Schwartz Date: Sun, 9 Jan 2005 17:15:09 +0000 Subject: [PATCH] Minor example changes; incorporating user notes git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@176739 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/pgsql/functions/pg-fetch-array.xml | 30 ++++++++++++------- reference/pgsql/functions/pg-fetch-assoc.xml | 9 +++++- reference/pgsql/functions/pg-fetch-object.xml | 7 ++--- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/reference/pgsql/functions/pg-fetch-array.xml b/reference/pgsql/functions/pg-fetch-array.xml index e58b4db87c..252a9262ef 100644 --- a/reference/pgsql/functions/pg-fetch-array.xml +++ b/reference/pgsql/functions/pg-fetch-array.xml @@ -1,5 +1,5 @@ - + @@ -37,10 +37,11 @@ result_type is a constant and can take the following values: PGSQL_ASSOC, PGSQL_NUM, and PGSQL_BOTH. - pg_fetch_array returns associative array - that has field name as key for PGSQL_ASSOC, field index as key - with PGSQL_NUM and both field name/index as key with - PGSQL_BOTH. Default is PGSQL_BOTH. + Using PGSQL_NUM, pg_fetch_array + will return an array with numerical indices, using + PGSQL_ASSOC will return only associative indices + while PGSQL_BOTH, the default, will return both + numerical and associative indices. result_type was added in PHP 4.0. @@ -65,17 +66,26 @@ if (!$conn) { exit; } -$result = pg_query($conn, "SELECT * FROM authors"); +$result = pg_query($conn, "SELECT author, email FROM authors"); if (!$result) { echo "An error occured.\n"; exit; } $arr = pg_fetch_array($result, 0, PGSQL_NUM); -echo $arr[0] . " <- array\n"; +echo $arr[0] . " <- Row 1 Author\n"; +echo $arr[1] . " <- Row 1 E-mail\n"; -$arr = pg_fetch_array($result, 1, PGSQL_ASSOC); -echo $arr["author"] . " <- array\n"; +// As of PHP 4.1.0, the row parameter is optional; NULL can be passed instead, +// to pass a result_type. Successive calls to pg_fetch_array will return the +// next row. +$arr = pg_fetch_array($result, NULL, PGSQL_ASSOC); +echo $arr["author"] . " <- Row 2 Author\n"; +echo $arr["email"] . " <- Row 2 E-mail\n"; + +$arr = pg_fetch_array($result); +echo $arr["author"] . " <- Row 3 Author\n"; +echo $arr[1] . " <- Row 3 E-mail\n"; ?> ]]> @@ -86,7 +96,7 @@ echo $arr["author"] . " <- array\n"; From 4.1.0, row became optional. Calling pg_fetch_array will increment - internal row counter by 1. + the internal row counter by one. diff --git a/reference/pgsql/functions/pg-fetch-assoc.xml b/reference/pgsql/functions/pg-fetch-assoc.xml index cf3e96327c..9178e7a22d 100644 --- a/reference/pgsql/functions/pg-fetch-assoc.xml +++ b/reference/pgsql/functions/pg-fetch-assoc.xml @@ -1,5 +1,5 @@ - + @@ -63,6 +63,13 @@ while ($row = pg_fetch_assoc($result)) { + + + From 4.1.0, row became optional. + Calling pg_fetch_assoc will increment + the internal row counter by one. + + See also pg_fetch_row, diff --git a/reference/pgsql/functions/pg-fetch-object.xml b/reference/pgsql/functions/pg-fetch-object.xml index 7fd7c68aea..56d350c302 100644 --- a/reference/pgsql/functions/pg-fetch-object.xml +++ b/reference/pgsql/functions/pg-fetch-object.xml @@ -1,5 +1,5 @@ - + @@ -38,9 +38,6 @@ insignificant). - - From 4.1.0, row is optional. - From 4.3.0, result_type is default to PGSQL_ASSOC while older versions' default was PGSQL_BOTH. There is no use for numeric property, @@ -88,7 +85,7 @@ pg_close($db_conn); From 4.1.0, row became optional. Calling pg_fetch_object will increment - internal row counter counter by 1. + the internal row counter counter by one.