Add examples, elaborate slightly on PDOStatement::fetchAll.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@173068 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Dan Scott 2004-11-19 22:21:35 +00:00
parent a16f547def
commit 243267c301
2 changed files with 125 additions and 21 deletions

View file

@ -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>
@ -22,10 +22,6 @@
<para>
<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
@ -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>

View file

@ -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>