cvs: peardoc /en/package/database/mdb2 intro-sequences.xml
| From: | Lukas Smith | Date: | Fri, 04 Aug 2006 14:41:16 +0000 |
| Subject: | cvs: peardoc /en/package/database/mdb2 intro-sequences.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-8218@lists.php.net to get a copy of this message | ||
lsmith Fri Aug 4 14:41:16 2006 UTC
Modified files:
/peardoc/en/package/database/mdb2 intro-sequences.xml
Log:
- added documentation for get*ID() methods
- added example for lastInsertID() method
http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb2/intro-sequences.xml?r1=1.7&r2=1.8&diff_format=u
Index: peardoc/en/package/database/mdb2/intro-sequences.xml
diff -u peardoc/en/package/database/mdb2/intro-sequences.xml:1.7
peardoc/en/package/database/mdb2/intro-sequences.xml:1.8
--- peardoc/en/package/database/mdb2/intro-sequences.xml:1.7 Mon May 8 06:44:44 2006
+++ peardoc/en/package/database/mdb2/intro-sequences.xml Fri Aug 4 14:41:16 2006
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
-<!-- $Revision: 1.7 $ -->
-
-<!-- add information on the following methods:
-lastInsertID(), getBeforeID(), getAfterID() -->
+<!-- $Revision: 1.8 $ -->
<refentry id="package.database.mdb2.intro-sequences">
<refnamediv>
@@ -99,7 +96,7 @@
</warning>
</refsect1>
- <refsect1 id="package.database.mdb2.intro-autoincrement.desc">
+ <refsect1 id="package.database.mdb2.intro-sequences.lastinsertid">
&title.desc;
<para>
If you prefer using <command>AUTO_INCREMENT</command> you can alternatively
@@ -107,19 +104,82 @@
<function>lastInsertID</function></ulink> method to retrieve the last
generated value.
</para>
+
+ <para>
+ <example>
+ <title>Using a sequence</title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid MDB2 object named $mdb2...
+$res =& $mdb2->query("INSERT INTO myTable (id, text) VALUES (NULL,
'foo')");
+
+// optionally pass in a table and fieldname in order to call nextId()
+// when autoincrement is not supported
+$id = $mdb2->lastInsertId('myTable', 'id');
+if (PEAR::isError($id)) {
+ die($id->getMessage());
+}
+
+?>
+ ]]>
+ </programlisting>
+ </example>
+ </para>
+ </refsect1>
+
+
+ <refsect1 id="package.database.mdb2.intro-sequences.getbeforeid">
+ &title.desc;
+ <para>
+ Finally if you prefer using what ever native feature the RDBMS supports you
+ can use the <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Extended.html#methodgetBeforeID">
+ <function>getBeforeID</function></ulink> and
+ <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Extended.html#methodgetAfterID">
+ <function>getAfterID</function></ulink> methods from the
+ <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Extended.html">
+ Extended</ulink> module. This way MDB2 will automatically use
+ <command>AUTO_INCREMENT</command> if its natively supported. If not MDB2 will
+ instead use a sequence to get the next id.
+ </para>
+
+ <para>
+ <example>
+ <title>Using a sequence</title>
+ <programlisting role="php">
+ <![CDATA[
+<?php
+// Once you have a valid MDB2 object named $mdb2...
+// $id may either be a quoted integer or php null
+$id = $mdb2->getBeforeID('myTable', 'id', true, true);
+if (PEAR::isError($id)) {
+ die($id->getMessage());
+}
+
+$res =& $mdb2->query("INSERT INTO myTable (id, text) VALUES ($id,
'foo')");
+
+// $id is now equivalent to the value in the id field that was inserted
+$id = $mdb2->getAfterID($id, 'myTable', 'id');
+if (PEAR::isError($id)) {
+ die($id->getMessage());
+}
+
+?>
+ ]]>
+ </programlisting>
+ </example>
+ </para>
</refsect1>
<refsect1 id="package.database.mdb2.intro-sequences.see">
&title.see;
<para>
- <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodnextID">
- <function>nextID</function></ulink>,
- <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodlastInsertID">
- <function>lastInsertID</function></ulink>,
<ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html#methodcreateSequence">
<function>createSequence</function></ulink>,
<ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html#methoddropSequence">
- <function>dropSequence</function></ulink>
+ <function>dropSequence</function></ulink>,
+ <ulink url="http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Manager_Common.html#methodlistSequences">
+ <function>listSequences</function></ulink>
</para>
</refsect1>
</refentry>