cvs: peardoc /en/package/database/db intro-fetch.xml

From: Date: Sat, 06 Mar 2004 04:37:54 +0000
Subject: cvs: peardoc /en/package/database/db intro-fetch.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-2878@lists.php.net to get a copy of this message
danielc Fri Mar 5 23:37:54 2004 EDT Modified files: /peardoc/en/package/database/db intro-fetch.xml Log: DB_FETCHMODE_OBJECT returns stdClass by default, not DB_row, though DB_row can be returned if parameer is used. Clarify this and add examples of both. http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-fetch.xml?r1=1.14&r2=1.15&ty=u Index: peardoc/en/package/database/db/intro-fetch.xml diff -u peardoc/en/package/database/db/intro-fetch.xml:1.14 peardoc/en/package/database/db/intro-fetch.xml:1.15 --- peardoc/en/package/database/db/intro-fetch.xml:1.14 Thu Feb 5 00:07:57 2004 +++ peardoc/en/package/database/db/intro-fetch.xml Fri Mar 5 23:37:53 2004 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.14 $ --> +<!-- $Revision: 1.15 $ --> <refentry id="package.database.db.intro-fetch"> <refnamediv> <refname>Introduction - Fetch &amp; Get</refname> @@ -129,40 +129,85 @@ <constant>DB_FETCHMODE_OBJECT</constant> </para> <para> - Returns a &class.db-row; object with column names - as properties + 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 as object</title> + <title>Fetching into an object</title> <programlisting role="php"> <![CDATA[ <?php // Once you have a valid DB object named $db... -$res =& $db->query('SELECT id, name, email FROM users'); -$row =& $res->fetchRow(DB_FETCHMODE_OBJECT); + +$res =& $db->query('INSERT INTO phptest ' + . "(a, b) VALUES (28, 'hi')"); + +$db->setFetchMode(DB_FETCHMODE_OBJECT); + +$res =& $db->query('SELECT * FROM phptest WHERE a = 28'); +$row =& $res->fetchRow(); + +print_r($row); +echo 'Column a is ' . $row->a; /* - * $row will contain: - * db_row Object + * Output... + * stdClass Object * ( - * [id] => <column "id" data>, - * [name] => <column "name" data>, - * [email] => <column "email" data> + * [a] => 28 + * [b] => hi * ) + * Column a is 28 */ +?> + ]]> + </programlisting> + </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... -// Access the data with: -$id = $row->id; -$name = $row->name; -$email = $row->email; +$res =& $db->query('INSERT INTO phptest ' + . "(a, b) VALUES (28, 'hi')"); + +$db->setFetchMode(DB_FETCHMODE_OBJECT, 'DB_row'); + +$res =& $db->query('SELECT * FROM phptest WHERE a = 28'); +$row =& $res->fetchRow(); + +print_r($row); +echo 'Column a is ' . $row->a; + +/* + * Output... + * db_row Object + * ( + * [a] => 28 + * [b] => hi + * ) + * Column a is 28 + */ ?> -]]> - </programlisting> - </example> + ]]> + </programlisting> + </example> </para> </listitem> </itemizedlist> </para> </refsect2> + <refsect2> <title>Set the format of the fetched row</title> <para>

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