cvs: peardoc /en/package/database/mdb2 intro-execute.xml
| From: | Lukas Smith | Date: | Mon, 07 Aug 2006 11:12:08 +0000 |
| Subject: | cvs: peardoc /en/package/database/mdb2 intro-execute.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-8254@lists.php.net to get a copy of this message | ||
lsmith Mon Aug 7 11:12:08 2006 UTC
Modified files:
/peardoc/en/package/database/mdb2 intro-execute.xml
Log:
- added information about setLimit() and free()
http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb2/intro-execute.xml?r1=1.10&r2=1.11&diff_format=u
Index: peardoc/en/package/database/mdb2/intro-execute.xml
diff -u peardoc/en/package/database/mdb2/intro-execute.xml:1.10
peardoc/en/package/database/mdb2/intro-execute.xml:1.11
--- peardoc/en/package/database/mdb2/intro-execute.xml:1.10 Fri Aug 4 23:33:07 2006
+++ peardoc/en/package/database/mdb2/intro-execute.xml Mon Aug 7 11:12:07 2006
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
-<!-- $Revision: 1.10 $ -->
+<!-- $Revision: 1.11 $ -->
<!--
-add information on the following methods:
-bindParam(), bindParamArray(), bindValue(), bindValueArray(), free()
+todos:
-add information about MDB2 type handling
+add information on the following methods:
+bindParam(), bindParamArray(), bindValue(), bindValueArray()
-->
@@ -31,6 +31,7 @@
same query several times but with different values in it,
such as adding a list of addresses into a database.
</para>
+
<para>
Another place prepare/execute is useful is supporting
databases which have different SQL syntaxes.
@@ -71,9 +72,12 @@
<title>Prepare</title>
<para>
To use the features above, you have to do two steps. Step one is to
- <emphasis>prepare</emphasis> the statement and the second is
- to <emphasis>execute</emphasis> it.
+ <emphasis>prepare</emphasis> the statement which returns an instance
+ of the <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Statement_Common.html">
+ MDB2_Statement_Common</ulink> class.
+ The second step is to <emphasis>execute</emphasis> it.
</para>
+
<para>
To start out, you need to
<ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodprepare">
@@ -103,6 +107,7 @@
<ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Statement_Common.html#methodexecute">
<function>execute</function></ulink>.
</para>
+
<para>
<ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodprepare">
<function>prepare</function></ulink> can handle different types of
@@ -112,6 +117,7 @@
data types</ulink> as the second parameter makes it
possible to set a specific type for each placeholder.
</para>
+
<para>
Since DML (data manipulation language - INSERT, UPDATE, DELETE) statements
have different return values than data fetches the
@@ -324,6 +330,66 @@
</para>
</refsect2>
+ <refsect2 id="package.database.mdb2.intro-execute.desc.free">
+ <title>Freeing Prepares Statements</title>
+ <para>
+ Once you finish using a repared statements, if your script
+ continues for a while, it's a good idea to save
+ memory by freeing the prepared statement set via
+ Use <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Statement_Common.html#methodfree">
+ <function>free</function></ulink>.
+ <example>
+ <title>Freeing</title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid MDB2 object named $mdb2...
+$sth = $mdb2->prepare('SELECT name, lang FROM numbers WHERE id = ?',
array('integer'), array('text', 'text'));
+
+$result = $sth->execute(1);
+
+$sth->free();
+?>
+$res->free();
+?>
+ ]]>
+ </programlisting>
+ </example>
+ </para>
+ </refsect2>
+
+ <refsect2 id="package.database.mdb2.intro-execute.desc.setlimit">
+ <title>Limiting rows and reading from an offset</title>
+ <para>
+ In order to read/write to only a limited number of rows from a result set
+ and/or to start reading from a specific offset the
+ <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodsetLimit">
+ <function>setLimit</function></ulink> can be called prior to calling
+ <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodprepare">
+ <function>prepare</function></ulink>.
+ The limit and offset will only affected the next method call that
+ will issue a query or prepare a statement and will automatically be reset
+ after issueing the query. This also applies to any internal queries issues
+ inside MDB2. Note that limit may not work with DML statements on RDBMS that
+ emulate limit support and no error will be raised.
+ </para>
+
+ <example>
+ <title>Using exec to manipulate data</title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid MDB2 object named $mdb2...
+// read 20 rows with an offset of 10
+$mdb2->setLimit(20, 10);
+$sth = $mdb2->prepare('SELECT name, lang FROM numbers WHERE group_id = ?',
array('integer'), array('text', 'text'));
+
+?>
+ ]]>
+ </programlisting>
+ </example>
+ </refsect2>
+
</refsect1>
</refentry>