cvs: peardoc /en/package/database/db/db-common getone.xml getrow.xml
| From: | Daniel Convissor | Date: | Thu, 15 Apr 2004 06:39:17 +0000 |
| Subject: | cvs: peardoc /en/package/database/db/db-common getone.xml getrow.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-3476@lists.php.net to get a copy of this message | ||
danielc Thu Apr 15 02:39:17 2004 EDT
Modified files:
/peardoc/en/package/database/db/db-common getone.xml getrow.xml
Log:
Add more thorough examples.
http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/getone.xml?r1=1.22&r2=1.23&ty=u
Index: peardoc/en/package/database/db/db-common/getone.xml
diff -u peardoc/en/package/database/db/db-common/getone.xml:1.22
peardoc/en/package/database/db/db-common/getone.xml:1.23
--- peardoc/en/package/database/db/db-common/getone.xml:1.22 Thu Apr 15 01:40:41 2004
+++ peardoc/en/package/database/db/db-common/getone.xml Thu Apr 15 02:39:17 2004
@@ -1,4 +1,4 @@
-<!-- $Revision: 1.22 $ -->
+<!-- $Revision: 1.23 $ -->
<refentry id="package.database.db.db-common.getone">
<refnamediv>
@@ -169,13 +169,57 @@
<![CDATA[
<?php
// Once you have a valid DB object named $db...
-$numrows = $db->getOne('select count(id) from clients');
+$data =& $db->getOne('SELECT cf FROM foo');
-if (DB::isError($numrows)) {
- die($numrows->getMessage());
+if (DB::isError($data)) {
+ die($data->getMessage());
}
-// Returns: 3
+echo "$data\n";
+?>
+ ]]>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>
+ Using <function>getOne</function>
+ with one placeholder
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+$data =& $db->getOne('SELECT cf FROM foo WHERE nf = ?',
+ 5);
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+echo "$data\n";
+?>
+ ]]>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>
+ Using <function>getOne</function>
+ with two placeholders
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+$data =& $db->getOne('SELECT cf FROM foo WHERE nf IN (?, ?)',
+ array(5, 10));
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+echo "$data\n";
?>
]]>
</programlisting>
http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/getrow.xml?r1=1.23&r2=1.24&ty=u
Index: peardoc/en/package/database/db/db-common/getrow.xml
diff -u peardoc/en/package/database/db/db-common/getrow.xml:1.23
peardoc/en/package/database/db/db-common/getrow.xml:1.24
--- peardoc/en/package/database/db/db-common/getrow.xml:1.23 Thu Apr 15 01:40:41 2004
+++ peardoc/en/package/database/db/db-common/getrow.xml Thu Apr 15 02:39:17 2004
@@ -1,4 +1,4 @@
-<!-- $Revision: 1.23 $ -->
+<!-- $Revision: 1.24 $ -->
<refentry id="package.database.db.db-common.getrow">
<refnamediv>
@@ -187,22 +187,143 @@
<refsect1 id="package.database.db.db-common.getrow.example">
&title.example;
<example>
- <title>Using <function>getRow</function></title>
+ <title>
+ Using <function>getRow</function> with
+ <parameter>$fetchmode</parameter> =
+ <constant>DB_FETCHMODE_ORDERED</constant>
+ </title>
<programlisting role="php">
<![CDATA[
<?php
// Once you have a valid DB object named $db...
-$row =& $db->getRow('select name, address from clients');
+$data =& $db->getRow('SELECT cf, df FROM foo',
+ array(), DB_FETCHMODE_ORDERED);
-if (DB::isError($row)) {
- die($row->getMessage());
+if (DB::isError($data)) {
+ die($data->getMessage());
}
-echo $row['name'] . ', ' . $row['address'] . "\n";
+print_r($data);
+
+/*
+ * Array
+ * (
+ * [0] => Juan
+ * [1] => 1991-01-11 21:31:41
+ * )
+ */
+?>
+ ]]>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>
+ Using <function>getRow</function> with
+ <parameter>$fetchmode</parameter> =
+ <constant>DB_FETCHMODE_ASSOC</constant>
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+$data =& $db->getRow('SELECT cf, df FROM foo',
+ array(), DB_FETCHMODE_ASSOC);
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+print_r($data);
+
+/*
+ * Array
+ * (
+ * [cf] => Juan
+ * [df] => 1991-01-11 21:31:41
+ * )
+ */
+?>
+ ]]>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>
+ Using <function>getRow</function> with
+ <parameter>$fetchmode</parameter> =
+ <constant>DB_FETCHMODE_OBJECT</constant>
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+$data =& $db->getRow('SELECT cf, df FROM foo',
+ array(), DB_FETCHMODE_OBJECT);
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+print_r($data);
+
+/*
+ * stdClass Object
+ * (
+ * [cf] => Juan
+ * [df] => 1991-01-11 21:31:41
+ * )
+ */
?>
]]>
</programlisting>
</example>
+
+ <example>
+ <title>
+ Using <function>getRow</function>
+ with one placeholder
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+$data =& $db->getRow('SELECT cf, df FROM foo WHERE nf = ?',
+ array(5));
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+// ...
+?>
+ ]]>
+ </programlisting>
+ </example>
+
+ <example>
+ <title>
+ Using <function>getRow</function>
+ with two placeholders
+ </title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid DB object named $db...
+
+$data =& $db->getRow('SELECT cf, df FROM foo WHERE nf IN (?, ?)',
+ array(5, 10));
+
+if (DB::isError($data)) {
+ die($data->getMessage());
+}
+
+// ...
+?>
+ ]]>
+ </programlisting>
+ </example>
+
</refsect1>
<refsect1 id="package.database.db.db-common.getrow.see">