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

From: Date: Sun, 08 Aug 2004 23:14:56 +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-4730@lists.php.net to get a copy of this message
danielc Sun Aug 8 19:14:56 2004 EDT Modified files: /peardoc/en/package/database/db/db-common setfetchmode.xml Log: * Add examples for using object mode with your own object. * Add ID's for the examples so they can be hyperlinked to. http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/setfetchmode.xml?r1=1.25&r2=1.26&ty=u Index: peardoc/en/package/database/db/db-common/setfetchmode.xml diff -u peardoc/en/package/database/db/db-common/setfetchmode.xml:1.25 peardoc/en/package/database/db/db-common/setfetchmode.xml:1.26 --- peardoc/en/package/database/db/db-common/setfetchmode.xml:1.25 Sat May 1 12:57:29 2004 +++ peardoc/en/package/database/db/db-common/setfetchmode.xml Sun Aug 8 19:14:56 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.25 $ --> +<!-- $Revision: 1.26 $ --> <refentry id="package.database.db.db-common.setfetchmode"> <refnamediv> @@ -138,7 +138,7 @@ <refsect1 id="package.database.db.db-common.setfetchmode.example"> &title.example; - <example> + <example id="package.database.db.db-common.setfetchmode.example.ordered"> <title> <constant>DB_FETCHMODE_ORDERED</constant> (default) </title> @@ -175,7 +175,7 @@ </screen> </example> - <example> + <example id="package.database.db.db-common.setfetchmode.example.assoc"> <title> <constant>DB_FETCHMODE_ASSOC</constant> </title> @@ -212,7 +212,7 @@ </screen> </example> - <example> + <example id="package.database.db.db-common.setfetchmode.example.object"> <title> <constant>DB_FETCHMODE_OBJECT</constant> </title> @@ -248,7 +248,7 @@ </screen> </example> - <example> + <example id="package.database.db.db-common.setfetchmode.example.objectdbrow"> <title> <constant>DB_FETCHMODE_OBJECT</constant> and &class.db-row; </title> @@ -278,6 +278,92 @@ <screen> <![CDATA[ db_row Object +( + [a] => 28 + [b] => hi +) +Column a is 28 + ]]> + </screen> + </example> + + <example id="package.database.db.db-common.setfetchmode.example.object4"> + <title> + <constant>DB_FETCHMODE_OBJECT</constant> with your own object in PHP 4 + </title> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... + +class SomeResult { + function SomeResult($data) { + foreach ($data as $key => $value) { + $this->$key = $data[$key]; + } + } +} + +$db->setFetchMode(DB_FETCHMODE_OBJECT, 'SomeResult'); + +$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[ +SomeResult Object +( + [a] => 28 + [b] => hi +) +Column a is 28 + ]]> + </screen> + </example> + + <example id="package.database.db.db-common.setfetchmode.example.object5"> + <title> + <constant>DB_FETCHMODE_OBJECT</constant> with your own object in PHP 5 + </title> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... + +class SomeResult { + public $row_data; + function __construct($data) { + $this->row_data = $data; + } + function __get($variable) { + return $this->row_data[$variable]; + } +} + +$db->setFetchMode(DB_FETCHMODE_OBJECT, 'SomeResult'); + +$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[ +SomeResult Object ( [a] => 28 [b] => hi

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