cvs: peardoc /en/package/database/db intro-fetch.xml
| From: | Daniel Convissor | Date: | Fri, 16 Apr 2004 17:38:44 +0000 |
| Subject: | cvs: peardoc /en/package/database/db intro-fetch.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-3555@lists.php.net to get a copy of this message | ||
danielc Fri Apr 16 13:38:44 2004 EDT
Modified files:
/peardoc/en/package/database/db intro-fetch.xml
Log:
Simplify .desc.format section.
http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-fetch.xml?r1=1.27&r2=1.28&ty=u
Index: peardoc/en/package/database/db/intro-fetch.xml
diff -u peardoc/en/package/database/db/intro-fetch.xml:1.27
peardoc/en/package/database/db/intro-fetch.xml:1.28
--- peardoc/en/package/database/db/intro-fetch.xml:1.27 Thu Apr 15 17:55:27 2004
+++ peardoc/en/package/database/db/intro-fetch.xml Fri Apr 16 13:38:44 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
-<!-- $Revision: 1.27 $ -->
+<!-- $Revision: 1.28 $ -->
<refentry id="package.database.db.intro-fetch">
<refnamediv>
@@ -64,171 +64,52 @@
</refsect2>
<refsect2 id="package.database.db.intro-fetch.desc.format">
- <title>Choosing Formats for Fetched Rows</title>
+ <title>Formats of Fetched Rows</title>
<para>
- The fetch modes supported are:
- <itemizedlist>
- <listitem>
- <para>
- <constant>DB_FETCHMODE_ORDERED</constant> (default)
- </para>
- <para>
- The <function>fetch*</function> returns an ordered array.
- The order is taken from the select statement.
- <example>
- <title>Fetch a ordered array</title>
- <programlisting role="php">
- <![CDATA[
-<?php
-// Once you have a valid DB object named $db...
-$db->setFetchMode(DB_FETCHMODE_ORDERED);
-$res =& $db->query('INSERT INTO phptest '
- . "(a, b) VALUES (28, 'hi')");
-$res =& $db->query('SELECT * FROM phptest WHERE a = 28');
-$row =& $res->fetchRow();
+ The data from the row of a query result can be
+ placed into one of three constructs:
+ an ordered array (with column numbers as keys),
+ an associative array (with column names as keys) or
+ an object (with column names as properties).
+ </para>
-print_r($row);
-echo 'Column a is ' . $row[0];
-?>
- ]]>
- </programlisting>
- <para>
- Output:
- </para>
- <screen>
- <![CDATA[
+ <para>
+ <constant>DB_FETCHMODE_ORDERED</constant> (default)
+ <screen>
+ <![CDATA[
Array
(
[0] => 28
[1] => hi
)
-Column a is 28
- ]]>
- </screen>
- </example>
- </para>
- </listitem>
- <listitem>
- <para>
- <constant>DB_FETCHMODE_ASSOC</constant>
- </para>
- <para>
- Returns an associative array with the column
- names as the array keys
- <example>
- <title>Fetch an associative array</title>
- <programlisting role="php">
- <![CDATA[
-<?php
-// Once you have a valid DB object named $db...
-$db->setFetchMode(DB_FETCHMODE_ASSOC);
-$res =& $db->query('INSERT INTO phptest '
- . "(a, b) VALUES (28, 'hi')");
-$res =& $db->query('SELECT * FROM phptest WHERE a = 28');
-$row =& $res->fetchRow();
+ ]]>
+ </screen>
+ </para>
-print_r($row);
-echo 'Column a is ' . $row['a'];
-?>
- ]]>
- </programlisting>
- <para>
- Output:
- </para>
- <screen>
- <![CDATA[
+ <para>
+ <constant>DB_FETCHMODE_ASSOC</constant>
+ <screen>
+ <![CDATA[
Array
(
[a] => 28
[b] => hi
)
-Column a is 28
- ]]>
- </screen>
- </example>
- </para>
- </listitem>
- <listitem>
- <para>
- <constant>DB_FETCHMODE_OBJECT</constant>
- </para>
- <para>
- Returns an object with column names as properties
- </para>
- <para>
- If <function>setFetchMode</function> is called without the optional
- second argument, <function>fetchRow</function> returns a
- <classname>stdClass</classname> object.
- <example>
- <title>Fetching into an object</title>
- <programlisting role="php">
- <![CDATA[
-<?php
-// Once you have a valid DB object named $db...
-$db->setFetchMode(DB_FETCHMODE_OBJECT);
-$res =& $db->query('INSERT INTO phptest '
- . "(a, b) VALUES (28, 'hi')");
-$res =& $db->query('SELECT * FROM phptest WHERE a = 28');
-$row =& $res->fetchRow();
+ ]]>
+ </screen>
+ </para>
-print_r($row);
-echo 'Column a is ' . $row->a;
-?>
- ]]>
- </programlisting>
- <para>
- Output:
- </para>
- <screen>
- <![CDATA[
+ <para>
+ <constant>DB_FETCHMODE_OBJECT</constant>
+ <screen>
+ <![CDATA[
stdClass Object
(
[a] => 28
[b] => hi
)
-Column a is 28
- ]]>
- </screen>
- </example>
- </para>
- <para>
- If <function>setFetchMode</function>'s optional parameter is passed
- <literal>DB_row</literal>, <function>fetchRow</function> returns a
- &class.db-row; object.
- <example>
- <title>Fetching into a DB_row object</title>
- <programlisting role="php">
- <![CDATA[
-<?php
-// Once you have a valid DB object named $db...
-$db->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row');
-$res =& $db->query('INSERT INTO phptest '
- . "(a, b) VALUES (28, 'hi')");
-$res =& $db->query('SELECT * FROM phptest WHERE a = 28');
-$row =& $res->fetchRow();
-
-print_r($row);
-echo 'Column a is ' . $row->a;
-?>
- ]]>
- </programlisting>
- <para>
- Output:
- </para>
- <screen>
- <![CDATA[
-db_row Object
-(
- [a] => 28
- [b] => hi
-)
-Column a is 28
- ]]>
- </screen>
- </example>
- </para>
- </listitem>
- </itemizedlist>
+ ]]>
+ </screen>
</para>
</refsect2>