cvs: phpdoc /en/reference/pdo/functions PDOStatement-fetch.xml PDOStatement-fetchAll.xml

From: Date: Fri, 19 Nov 2004 22:21:35 +0000
Subject: cvs: phpdoc /en/reference/pdo/functions PDOStatement-fetch.xml PDOStatement-fetchAll.xml
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969365141@lists.php.net to get a copy of this message
dbs Fri Nov 19 17:21:35 2004 EDT Modified files: /phpdoc/en/reference/pdo/functions PDOStatement-fetch.xml PDOStatement-fetchAll.xml Log: Add examples, elaborate slightly on PDOStatement::fetchAll. http://cvs.php.net/diff.php/phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml?r1=1.1&r2=1.2&ty=u Index: phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml diff -u phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml:1.1 phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml:1.2 --- phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml:1.1 Wed Nov 10 17:21:23 2004 +++ phpdoc/en/reference/pdo/functions/PDOStatement-fetch.xml Fri Nov 19 17:21:35 2004 @@ -1,5 +1,5 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> <refentry id="function.PDOStatement-fetch"> <refnamediv> @@ -23,10 +23,6 @@ <parameter>fetch_style</parameter> can be one of the following values: <itemizedlist> <listitem><para> - <literal>PDO_FETCH_NUM</literal>: returns an array indexed by column - number as returned in your result set, starting at column 0 - </para></listitem> - <listitem><para> <literal>PDO_FETCH_ASSOC</literal>: returns an array indexed by column name as returned in your result set </para></listitem> @@ -35,9 +31,9 @@ both column name and column number as returned in your result set </para></listitem> <listitem><para> - <literal>PDO_FETCH_OBJ</literal>: returns an anonymous object with - property names that correspond to the column names returned in your - result set + <literal>PDO_FETCH_BOUND</literal>: returns &true; and assigns the + values of the columns in your result set to the PHP variables to which + they were bound with the <function>PDO::bindParam</function> method </para></listitem> <listitem><para> <literal>PDO_FETCH_LAZY</literal>: combines @@ -45,13 +41,80 @@ creating the object variable names as they are accessed </para></listitem> <listitem><para> - <literal>PDO_FETCH_BOUND</literal>: returns &true; and assigns the - values of the columns in your result set to the PHP variables to which - they were bound with the <function>PDO::bindParam</function> method + <literal>PDO_FETCH_OBJ</literal>: returns an anonymous object with + property names that correspond to the column names returned in your + result set + </para></listitem> + <listitem><para> + <literal>PDO_FETCH_NUM</literal>: returns an array indexed by column + number as returned in your result set, starting at column 0 </para></listitem> </itemizedlist> </para> + <example><title>Fetching rows using different fetch styles</title> + <programlisting role="php"> +<![CDATA[ +<?php +/* Exercise PDOStatement::fetch styles */ +print("PDO_FETCH_ASSOC: "); +print("Return next row as an array indexed by column name\n"); +$result = $sth->fetch(PDO_FETCH_ASSOC); +print_r($result); +print("\n"); + +print("PDO_FETCH_BOTH: "); +print("Return next row as an array indexed by both column name and number\n"); +$result = $sth->fetch(PDO_FETCH_BOTH); +print_r($result); +print("\n"); + +print("PDO_FETCH_LAZY: "); +print("Return next row as an anonymous object with column names as properties\n"); +$result = $sth->fetch(PDO_FETCH_LAZY); +print_r($result); +print("\n"); + +print("PDO_FETCH_OBJ: "); +print("Return next row as an anonymous object with column names as properties\n"); +$result = $sth->fetch(PDO_FETCH_OBJ); +print $result->NAME; +print("\n"); +?> +]]> + </programlisting> + </example> + &example.outputs; + <screen> +<![CDATA[ +PDO_FETCH_ASSOC: Return next row as an array indexed by column name +Array +( + [NAME] => apple + [COLOUR] => red +) + +PDO_FETCH_BOTH: Return next row as an array indexed by both column name and number +Array +( + [NAME] => banana + [0] => banana + [COLOUR] => yellow + [1] => yellow +) + +PDO_FETCH_LAZY: Return next row as an anonymous object with column names as properties +PDORow Object +( + [NAME] => orange + [COLOUR] => orange +) + +PDO_FETCH_OBJ: Return next row as an anonymous object with column names as properties +kiwi +]]> + </screen> + </refsect1> </refentry> http://cvs.php.net/diff.php/phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml?r1=1.2&r2=1.3&ty=u Index: phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml diff -u phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml:1.2 phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml:1.3 --- phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml:1.2 Thu Nov 11 03:16:32 2004 +++ phpdoc/en/reference/pdo/functions/PDOStatement-fetchAll.xml Fri Nov 19 17:21:35 2004 @@ -1,27 +1,68 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> <refentry id="function.PDOStatement-fetchAll"> <refnamediv> <refname>PDOStatement::fetchAll</refname> <refpurpose> - Returns an array of all of the results + Returns an array containing all of the result set rows </refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>array</type><methodname>PDOStatement::fetchAll</methodname> - <methodparam choice="opt"><type>int</type><parameter>how</parameter></methodparam> + <methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam> </methodsynopsis> - &warn.undocumented.func; - <note> - <para> - <parameter>how</parameter> defaults to - <literal>PDO_FETCH_BOTH</literal>. - </para> - </note> + &warn.experimental.func; + <para> + <function>PDOStatement::fetchAll</function> returns an array containing + all of the remaining rows in the result set. The array represents each + row as either an array of column values or an object with properties + corresponding to each column name. <parameter>fetch_style</parameter> + controls the contents of the returned array as documented in + <function>PDOStatement::fetch</function>. <parameter>fetch_style</parameter> + defaults to <literal>PDO_FETCH_BOTH</literal>. + </para> + + <example><title>Fetch all remaining rows in a result set</title> + <programlisting role="php"> +<![CDATA[ +<?php +/* Fetch all of the remaining rows in the result set */ +print("Fetch all of the remaining rows in the result set:\n"); +$result = $sth->fetchAll(); +print_r($result); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +Fetch all of the remaining rows in the result set: +Array +( + [0] => Array + ( + [NAME] => pear + [0] => pear + [COLOUR] => green + [1] => green + ) + + [1] => Array + ( + [NAME] => watermelon + [0] => watermelon + [COLOUR] => pink + [1] => pink + ) + +) +]]> + </screen> + </example> </refsect1> </refentry>

« previous php.doc (#969365141) next »