cvs: peardoc /en/package/database/db/db-common setfetchmode.xml

From: Date: Fri, 16 Apr 2004 00:48:27 +0000
Subject: cvs: peardoc /en/package/database/db/db-common setfetchmode.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-3518@lists.php.net to get a copy of this message
danielc Thu Apr 15 20:48:27 2004 EDT Modified files: /peardoc/en/package/database/db/db-common setfetchmode.xml Log: Add examples of each basic fetch mode. http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/setfetchmode.xml?r1=1.19&r2=1.20&ty=u Index: peardoc/en/package/database/db/db-common/setfetchmode.xml diff -u peardoc/en/package/database/db/db-common/setfetchmode.xml:1.19 peardoc/en/package/database/db/db-common/setfetchmode.xml:1.20 --- peardoc/en/package/database/db/db-common/setfetchmode.xml:1.19 Thu Apr 15 14:44:26 2004 +++ peardoc/en/package/database/db/db-common/setfetchmode.xml Thu Apr 15 20:48:27 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.19 $ --> +<!-- $Revision: 1.20 $ --> <refentry id="package.database.db.db-common.setfetchmode"> <refnamediv> @@ -122,16 +122,154 @@ <refsect1 id="package.database.db.db-common.setfetchmode.example"> &title.example; <example> - <title>Using <function>setFetchMode</function></title> + <title> + <constant>DB_FETCHMODE_ORDERED</constant> (default) + </title> + <para> + Causes ordered arrays to be returned. + The order is taken from the select statement. + </para> <programlisting role="php"> <![CDATA[ <?php // Once you have a valid DB object named $db... $db->setFetchMode(DB_FETCHMODE_ORDERED); + +$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28'); +$row =& $res->fetchRow(); + +print_r($row); +echo 'Column a is ' . $row[0]; ?> ]]> </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +Array +( + [0] => 28 + [1] => hi +) +Column a is 28 + ]]> + </screen> </example> + + <example> + <title> + <constant>DB_FETCHMODE_ASSOC</constant> + </title> + <para> + Makes associative arrays, with the column + names as the array keys. + </para> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... +$db->setFetchMode(DB_FETCHMODE_ASSOC); + +$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28'); +$row =& $res->fetchRow(); + +print_r($row); +echo 'Column a is ' . $row['a']; +?> + ]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +Array +( + [a] => 28 + [b] => hi +) +Column a is 28 + ]]> + </screen> + </example> + + <example> + <title> + <constant>DB_FETCHMODE_OBJECT</constant> + </title> + <para> + Returns objects with column names as properties. + </para> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... +$db->setFetchMode(DB_FETCHMODE_OBJECT); + +$res =& $db->query('SELECT a, b FROM phptest WHERE a = 28'); +$row =& $res->fetchRow(); + +print_r($row); +echo 'Column a is ' . $row->a; +?> + ]]> + </programlisting> + <para> + Output: + </para> + <screen> + <![CDATA[ +stdClass Object +( + [a] => 28 + [b] => hi +) +Column a is 28 + ]]> + </screen> + </example> + + <example> + <title> + <constant>DB_FETCHMODE_OBJECT</constant> and &class.db-row; + </title> + <para> + If <function>setFetchMode</function>'s optional + <parameter>$object_class</parameter> parameter + is set to <literal>DB_row</literal>, &class.db-row; + objects are returned. + </para> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... +$db->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row'); + +$res =& $db->query('SELECT a, b 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> + </refsect1> </refentry>

« previous php.pear.doc (#3518) next »