cvs: phpdoc(REF_STRUCT_DEV) / manual.xml.in /en/reference/dba book.xml constants.xml examples.xml reference.xml setup.xml /en/reference/dbx book.xml
constants.xml reference.xml setup.xml /en/reference/sdo book.xml constants.xml examples.xml limitations.xml reference.xml setup.xml
/en/reference/sdodasrel book.xml constants.xml examples.xml limitations.xml reference.xml setup.xml /en/reference/uodbc book.xml constants.xml
reference.xml setup.xml
| From: | Hannes Magnusson | Date: | Fri, 07 Dec 2007 14:24:26 +0000 |
| Subject: | cvs: phpdoc(REF_STRUCT_DEV) / manual.xml.in /en/reference/dba book.xml constants.xml examples.xml reference.xml setup.xml /en/reference/dbx book.xml constants.xml reference.xml setup.xml /en/reference/sdo book.xml constants.xml examples.xml limitations.xml reference.xml setup.xml /en/reference/sdodasrel book.xml constants.xml examples.xml limitations.xml reference.xml setup.xml /en/reference/uodbc book.xml constants.xml reference.xml setup.xml |
||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-550@lists.php.net to get a copy of this message | ||
bjori Fri Dec 7 14:24:26 2007 UTC
Added files: (Branch: REF_STRUCT_DEV)
/phpdoc/en/reference/dba book.xml constants.xml examples.xml
setup.xml
/phpdoc/en/reference/dbx book.xml setup.xml
/phpdoc/en/reference/sdo book.xml examples.xml limitations.xml
setup.xml
/phpdoc/en/reference/sdodasrel book.xml examples.xml
limitations.xml setup.xml
/phpdoc/en/reference/uodbc book.xml setup.xml
Modified files:
/phpdoc manual.xml.in
/phpdoc/en/reference/dba reference.xml
/phpdoc/en/reference/dbx constants.xml reference.xml
/phpdoc/en/reference/sdo constants.xml reference.xml
/phpdoc/en/reference/sdodasrel constants.xml reference.xml
/phpdoc/en/reference/uodbc constants.xml reference.xml
Log:
Upgrade refs.database.abstract to the new-ref-struct-style
http://cvs.php.net/viewvc.cgi/phpdoc/manual.xml.in?r1=1.224.2.27&r2=1.224.2.28&diff_format=u Index: phpdoc/manual.xml.in diff -u phpdoc/manual.xml.in:1.224.2.27 phpdoc/manual.xml.in:1.224.2.28 --- phpdoc/manual.xml.in:1.224.2.27 Thu Dec 6 23:13:19 2007 +++ phpdoc/manual.xml.in Fri Dec 7 14:24:25 2007 @@ -2,7 +2,7 @@ <!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "@srcdir@/docbook/docbook-xml/docbook.dtd" [ -<!-- $Revision: 1.224.2.27 $ --> <!-- Last updated to comply to manual.xml.in 1.189 --> +<!-- $Revision: 1.224.2.28 $ --> <!-- Last updated to comply to manual.xml.in 1.189 --> <!-- We use xhtml entities all over the place --> <!ENTITY % xhtml-lat1 SYSTEM "@srcdir@/entities/ISO/xhtml1-lat1.ent"> <!ENTITY % xhtml-symbol SYSTEM "@srcdir@/entities/ISO/xhtml1-symbol.ent"> @@ -186,14 +186,14 @@ <set xml:id="refs.database"> <title>Database Extensions</title> - <book xml:id="refs.database.abstract"> + <set xml:id="refs.database.abstract"> <title>Abstraction Layers</title> - &reference.dba.reference; - &reference.dbx.reference; - &reference.sdo.reference; - &reference.sdodasrel.reference; - &reference.uodbc.reference; - </book> + &reference.dba.book; + &reference.dbx.book; + &reference.sdo.book; + &reference.sdodasrel.book; + &reference.uodbc.book; + </set> <book xml:id="book.pdo"> <title>PDO</title> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/reference.xml?r1=1.26.2.1&r2=1.26.2.2&diff_format=u Index: phpdoc/en/reference/dba/reference.xml diff -u phpdoc/en/reference/dba/reference.xml:1.26.2.1 phpdoc/en/reference/dba/reference.xml:1.26.2.2 --- phpdoc/en/reference/dba/reference.xml:1.26.2.1 Wed Oct 3 11:41:09 2007 +++ phpdoc/en/reference/dba/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,261 +1,10 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.26.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: bundled --> +<!-- $Revision: 1.26.2.2 $ --> <reference xml:id="ref.dba" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Database (dbm-style) Abstraction Layer Functions</title> <titleabbrev>dba</titleabbrev> - <partintro> - <section xml:id="dba.intro"> - &reftitle.intro; - <para> - These functions build the foundation for accessing Berkeley DB - style databases. - </para> - <para> - This is a general abstraction layer for several file-based databases. - As such, functionality is limited to a common subset of features - supported by modern databases such as - <link xlink:href="&url.sleepycat;">Sleepycat Software's DB2</link>. - (This is not to be confused with IBM's DB2 software, which is - supported through the <link linkend="ref.uodbc">ODBC functions</link>.) - </para> - </section> - <section xml:id="dba.requirements"> - &reftitle.required; - <para> - The behaviour of various aspects depends on the implementation of the - underlying database. Functions such as <function>dba_optimize</function> - and <function>dba_sync</function> will do what they promise for one - database and will do nothing for others. You have to download and install - supported dba-Handlers. - <table> - <title>List of DBA handlers</title> - <tgroup cols="2"> - <thead> - <row> - <entry>Handler</entry> - <entry>Notes</entry> - </row> - </thead> - <tbody> - <row> - <entry><literal>dbm</literal></entry> - <entry> - Dbm is the oldest (original) type of Berkeley DB style - databases. You should avoid it, if possible. We do not support - the compatibility functions built into DB2 and gdbm, because - they are only compatible on the source code level, but cannot - handle the original dbm format. - </entry> - </row> - - <row> - <entry><literal>ndbm</literal></entry> - <entry> - Ndbm is a newer type and more flexible than dbm. It still has - most of the arbitrary limits of dbm (therefore it is - deprecated). - </entry> - </row> - - <row> - <entry><literal>gdbm</literal></entry> - <entry> - Gdbm is the <link xlink:href="&url.gdbm;">GNU database - manager</link>. - </entry> - </row> - - <row> - <entry><literal>db2</literal></entry> - <entry> - DB2 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB2</link>. It is described as "a programmatic toolkit that - provides high-performance built-in database support for both - standalone and client/server applications. - </entry> - </row> - - <row> - <entry><literal>db3</literal></entry> - <entry> - DB3 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB3</link>. - </entry> - </row> - - <row> - <entry><literal>db4</literal></entry> - <entry> - DB4 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB4</link>. This is available since PHP 4.3.2. - </entry> - </row> - - <row> - <entry><literal>cdb</literal></entry> - <entry> - Cdb is "a fast, reliable, lightweight package for creating and - reading constant databases." It is from the author of qmail and - can be found at <link xlink:href="&url.cdb;">&url.cdb;</link>. Since it is - constant, we support only reading operations. And since PHP 4.3.0 - we support writing (not updating) through the internal cdb library. - </entry> - </row> - - <row> - <entry><literal>cdb_make</literal></entry> - <entry> - Since PHP 4.3.0 we support creation (not updating) of cdb files - when the bundled cdb library is used. - </entry> - </row> - - <row> - <entry><literal>flatfile</literal></entry> - <entry> - This is available since PHP 4.3.0 for compatibility with the deprecated - <link linkend="ref.dbm">dbm</link> extension only and should be avoided. - However you may use this where files were created in this format. That - happens when configure could not find any external library. - </entry> - </row> - - <row> - <entry><literal>inifile</literal></entry> - <entry> - This is available since PHP 4.3.3 to be able to modify php.ini files - from within PHP scripts. When working with ini files you can pass arrays - of the form array(0=>group,1=>value_name) or strings of the form - "[group]value_name" where group is optional. As the functions - <function>dba_firstkey</function> and <function>dba_nextkey</function> - return string representations of the key there is a new function - <function>dba_key_split</function> available since PHP 5 which allows - to convert the string keys into array keys without loosing &false;. - </entry> - </row> - - <row> - <entry><literal>qdbm</literal></entry> - <entry> - This is available since PHP 5.0.0. The qdbm library can be loaded from - <link xlink:href="http://qdbm.sourceforge.net">http://qdbm.sourceforge.net</link>. - </entry> - </row> - - </tbody> - </tgroup> - </table> - </para> - <para> - When invoking the <function>dba_open</function> or - <function>dba_popen</function> functions, one of the - handler names must be supplied as an argument. The actually - available list of handlers is displayed by invoking - <function>phpinfo</function> or <function>dba_handlers</function>. - </para> - </section> - - &reference.dba.configure; - - <section xml:id="dba.runtime"> - &reftitle.runtime; - &no.config; - </section> - - <section xml:id="dba.resources"> - &reftitle.resources; - <para> - The functions <function>dba_open</function> and - <function>dba_popen</function> return a handle to the specified - database file to access which is used by all other dba-function calls. - </para> - </section> - - <section xml:id="dba.constants"> - &reftitle.constants; - &no.constants; - </section> - - <section xml:id="dba.examples"> - &reftitle.examples; - <para> - <example> - <title>DBA example</title> - <programlisting role="php"> -<![CDATA[ -<?php - -$id = dba_open("/tmp/test.db", "n", "db2"); - -if (!$id) { - echo "dba_open failed\n"; - exit; -} - -dba_replace("key", "This is an example!", $id); - -if (dba_exists("key", $id)) { - echo dba_fetch("key", $id); - dba_delete("key", $id); -} - -dba_close($id); -?> -]]> - </programlisting> - </example> - </para> - <para> - DBA is binary safe and does not have any arbitrary limits. - However, it inherits all limits set by the underlying - database implementation. - </para> - <para> - All file-based databases must provide a way of setting the file - mode of a new created database, if that is possible at all. The - file mode is commonly passed as the fourth argument to - <function>dba_open</function> or <function>dba_popen</function>. - </para> - <para> - You can access all entries of a database in a linear way by using the - <function>dba_firstkey</function> and <function>dba_nextkey</function> - functions. You may not change the database while traversing it. - </para> - <para> - <example> - <title>Traversing a database</title> - <programlisting role="php"> -<![CDATA[ -<?php - -// ...open database... - -$key = dba_firstkey($id); - -while ($key != false) { - if (true) { // remember the key to perform some action later - $handle_later[] = $key; - } - $key = dba_nextkey($id); -} - -foreach ($handle_later as $val) { - dba_delete($val, $id); -} - -?> -]]> - </programlisting> - </example> - </para> - </section> - - </partintro> - &reference.dba.functions.entities; </reference> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/constants.xml?r1=1.11&r2=1.11.2.1&diff_format=u Index: phpdoc/en/reference/dbx/constants.xml diff -u phpdoc/en/reference/dbx/constants.xml:1.11 phpdoc/en/reference/dbx/constants.xml:1.11.2.1 --- phpdoc/en/reference/dbx/constants.xml:1.11 Wed Jun 20 22:24:21 2007 +++ phpdoc/en/reference/dbx/constants.xml Fri Dec 7 14:24:25 2007 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.11 $ --> - <section xml:id="constants.dbx" xmlns="http://docbook.org/ns/docbook"> +<!-- $Revision: 1.11.2.1 $ --> + <appendix xml:id="constants.dbx" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -236,7 +236,7 @@ </listitem> </varlistentry> </variablelist> - </section> + </appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/reference.xml?r1=1.20.2.1&r2=1.20.2.2&diff_format=u Index: phpdoc/en/reference/dbx/reference.xml diff -u phpdoc/en/reference/dbx/reference.xml:1.20.2.1 phpdoc/en/reference/dbx/reference.xml:1.20.2.2 --- phpdoc/en/reference/dbx/reference.xml:1.20.2.1 Wed Oct 3 11:41:09 2007 +++ phpdoc/en/reference/dbx/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,102 +1,8 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.20.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: pecl, external --> +<!-- $Revision: 1.20.2.2 $ --> <reference xml:id="ref.dbx" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> - <title>dbx Functions</title> - <titleabbrev>dbx</titleabbrev> - - <partintro> - <section xml:id="dbx.intro"> - &reftitle.intro; - <para> - The dbx module is a database abstraction layer (db 'X', where 'X' - is a supported database). The dbx functions allow you to access - all supported databases using a single calling convention. - The dbx-functions themselves do not interface directly to the - databases, but interface to the modules that are used to support - these databases. - </para> - <note> - <para> - &pecl.moved-ver;5.1.0. - </para> - </note> - </section> - - <section xml:id="dbx.required"> - &reftitle.required; - <para> - To be able to use a database with the dbx-module, the module must be either - linked or loaded into PHP, and the database module must be supported by the - dbx-module. Currently, the following databases are supported, but others - will follow: - <itemizedlist> - <listitem> - <simpara> - <link linkend="ref.fbsql">FrontBase</link> (available from PHP 4.1.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.mssql">Microsoft SQL Server</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.mysql">MySQL</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.uodbc">ODBC</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.pgsql">PostgreSQL</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.sybase">Sybase-CT</link> (available from PHP 4.2.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.oci8">Oracle (oci8)</link> (available from PHP 4.3.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.sqlite">SQLite</link> (PHP 5). - </simpara> - </listitem> - </itemizedlist> - </para> - <para> - Documentation for adding additional database support to dbx can be - found at <link xlink:href="&url.dbx.docs;">&url.dbx.docs;</link>. - </para> - </section> - - &reference.dbx.configure; - - &reference.dbx.ini; - - <section xml:id="dbx.resources"> - &reftitle.resources; - <para> - There are two resource types used in the dbx module. The first one is the - link-<type>object</type> for a database connection, the second a - result-<type>object</type> which holds the result of a query. - </para> - </section> - - &reference.dbx.constants; - - </partintro> + <title>dbx &Functions;</title> &reference.dbx.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/sdo/constants.xml diff -u phpdoc/en/reference/sdo/constants.xml:1.3 phpdoc/en/reference/sdo/constants.xml:1.3.2.1 --- phpdoc/en/reference/sdo/constants.xml:1.3 Wed Jun 20 22:25:19 2007 +++ phpdoc/en/reference/sdo/constants.xml Fri Dec 7 14:24:25 2007 @@ -1,7 +1,7 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.3.2.1 $ --> <!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> -<section xml:id="sdo.constants" xmlns="http://docbook.org/ns/docbook"> +<appendix xml:id="sdo.constants" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -50,7 +50,7 @@ </listitem> </varlistentry> </variablelist> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/reference.xml?r1=1.28.2.1&r2=1.28.2.2&diff_format=u Index: phpdoc/en/reference/sdo/reference.xml diff -u phpdoc/en/reference/sdo/reference.xml:1.28.2.1 phpdoc/en/reference/sdo/reference.xml:1.28.2.2 --- phpdoc/en/reference/sdo/reference.xml:1.28.2.1 Wed Oct 3 11:41:14 2007 +++ phpdoc/en/reference/sdo/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,247 +1,10 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.28.2.1 $ --> -<!-- Purpose: xml --> -<!-- Membership: pecl --> +<!-- $Revision: 1.28.2.2 $ --> <reference xml:id="ref.sdo" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> - <title>SDO Functions</title> - <titleabbrev>SDO</titleabbrev> + <title>SDO &Functions;</title> <partintro> - <section xml:id="sdo.intro"> - &reftitle.intro; - <para> - Service Data Objects (SDOs) enable PHP applications to work with - data from different sources (like a database query, an XML file, - and a spreadsheet) using a single interface. - </para> - <para> - Each different kind of data source requires a Data Access Service - (DAS) to provide access to the data in the data source. - In your PHP application, you use a DAS to create an SDO - instance that represents some data in the data source. You can then - set and get values in the SDO instance using the standard SDO - interface. Finally, you use a DAS to write the modified data back - to a data source, typically the same one. - </para> - <para> - See the - <link linkend="sdo.das.table">list of Data Access Services</link> - for details on those - currently available. In addition to the provided DASs, SDO also - provides interfaces to enable others to be implemented - (see the section on <link linkend="sdo.class.sdo-das-spis">SDO Data - Access Services Interface</link> for more details). - </para> - <para> - This extension is derived from concepts taken from the - <link xlink:href="&url.ibm.sdo;">Service Data Objects specification</link>. - It includes a version of the - <link xlink:href="&url.apache.tuscany;">Apache Tuscany</link> SDO for C++ project. - </para> - - <section xml:id="sdo.intro.structure"> - <title>The Structure of a Service Data Object</title> - <para> - A Service Data Object instance is made up of a tree of data objects. - The tree is defined by containment relationships between the data - objects. For example, a Company data object might consist of a number - of Department data objects and therefore the Company would have - a containment relationship to the Departments. - </para> - <para> An SDO may also have non-containment references between data objects in the - tree. For example, one Employee data object might reference another Employee to - identify a career mentor. - </para> - <para> - As well as data objects referencing each other, they can also have - primitive properties. For example, the Company data object might - have a property called "name" of type string, for holding the name - of the company (for example, "Acme"). - </para> - <para> Each of these properties of a data object - containment relationships, - non-containment references, or primitive properties - may be many-valued or - single-valued. In the above examples, Departments is many-valued and - the Company name is single-valued. - </para> - <para> In PHP, each SDO data object is represented as a PHP object. The properties of the - data object can be accessed using either object syntax or associative array syntax. - We'll see some examples of this later. - </para> - </section> - </section> - - <section xml:id="sdo.requirements"> - &reftitle.required; - <para> - The SDO extension requires PHP 5.1.0 or higher. It also requires the - libxml2 library. Normally libxml2 will already be installed, but if - not, it can be downloaded from - <link xlink:href='&url.libxml;'> - &url.libxml; - </link> - . - </para> - </section> - - <section xml:id="sdo.installation"> - &reftitle.install; - <note> - <para> - Earlier versions of the SDO extension required a separate shared - library for the XML DAS. This is now obsolete and any references to - <filename>php_sdo_das_xml.dll</filename> - or - <filename>sdo_das_xml.so</filename> - should be removed from your - &php.ini; - . - </para> - </note> - <procedure xml:id='sdo.install.unix'> - <title>Unix systems</title> - <step> - <para> - The three SDO components - the SDO core, the XML DAS and the - Relational DAS - are packaged together with Service Component - Architecture (SCA) into one PECL project, SCA_SDO, so you can - download SCA and all three parts of SDO with the command: - <screen> - <![CDATA[ -pecl install SCA_SDO -]]> - </screen> - </para> - <para> - This command will build the SDO shared library as well as - installing the PHP files that make up SCA and the SDO - Relational DAS. - </para> - <para> - If you want to use the latest beta version, then instead run: - <screen> - <![CDATA[ -pecl install SCA_SDO-beta -]]> - </screen> - </para> - </step> - <step> - <para> - The - <command>pecl</command> - command automatically installs the SDO module into your PHP - extensions directory. To enable the SDO extension you must add the - following line to - &php.ini; - : - <screen> - <![CDATA[ -extension=sdo.so -]]> - </screen> - </para> - <para> - For more information about building PECL packages, consult the - <link linkend="install.pecl">PECL installation</link> - section of the manual. - </para> - </step> - </procedure> - - <procedure xml:id='sdo.install.win32'> - <title>Windows</title> - <step> - <para> - The latest SDO DLL can be downloaded from - <link xlink:href='&url.pecl.win.ext;php_sdo.dll'>php_sdo.dll</link> - . - </para> - <para> - Note that currently the - <link xlink:href='&url.pecl.win;'>pecl4win</link> - site does not provide this binary at the current release level; - you can only download the latest level. - </para> - </step> - <step> - <para> - The - <command>pecl</command> - command automatically installs the SDO module into your PHP - extensions directory. To enable the SDO extension you must add the - following line to - &php.ini; - : - <screen> - <![CDATA[ -extension=php_sdo.dll -]]> - </screen> - </para> - </step> - <step> - <para> - The Relational DAS can be downloaded and installed with the - command: - <screen> - <![CDATA[ -pecl install -B sdo -]]> - </screen> - </para> - <para> - The Relational DAS is written in PHP. You may need to update your - <link linkend="ini.include-path">include_path</link> - in - &php.ini; - to point to the directory that contains - <filename>sdo/DAS/Relational</filename> - . - </para> - </step> - </procedure> - - <procedure xml:id='sdo.build.linux.steps'> - <title>Building SDO on Linux</title> - <para> - This section describes how to build the SDO core and XML DAS on - Linux. You would only need to know how to do this if you wish to - build a recent version that you have checked out of CVS. - </para> - <step> - <para> - Change to the main extension directory: - <command>cd < wherever your sdo code is ></command> - </para> - </step> - <step> - <para> - Run - <command>phpize</command> - , which will set up the environment to compile SDO. - </para> - </step> - <step> - <para> - Next, run - <command>./configure; make; make install</command> - . Please note, you may need to login as root to install the - extension. - </para> - </step> - <step> - <para> - Make sure that the module is loaded by PHP, by adding - <filename>extension=sdo.so</filename> - to your - &php.ini; - file. - </para> - </step> - </procedure> - </section> - <section xml:id="sdo.das.table"> <title>Data Access Services</title> <para> @@ -280,843 +43,7 @@ </para> </section> - <section xml:id='sdo.limitations'> - <title>Limitations</title> - <procedure xml:id='sdo.limitations.implementation'> - <title>Implementation Limitations</title> - <para> - The following are limitations in the current SDO implementation: - </para> - <step> - <para> - There is no support for multi-byte character sets. - This will be considered, depending on community requirements, - in the Unicode-enabled version of PHP. - See <link linkend="ref.unicode">Unicode Functions</link>. - </para> - </step> - </procedure> - <procedure xml:id='sdo.limitations.sdo'> - <title>SDO Limitations</title> - <para> - The following SDO 2.0 concepts are not supported in the current - PHP implementation. - It is not necessarily the case that these will all be added over time. - Their inclusion will depend on community requirements. - </para> - <step> - <para> - Bi-directional relationships. - </para> - </step> - <step> - <para> - Type and property alias names. - </para> - </step> - <step> - <para> - Read-only properties. - </para> - </step> - <step> - <para> - The Helper classes defined in SDO 2.0 are not directly implemented. - However equivalent function is provided in a more natural way for PHP. - For example the function of <command>CopyHelper::copy()</command> - is provided by applying the PHP - <link linkend='language.oop5.cloning'>clone</link> keyword to a data object. - </para> - </step> - </procedure> - </section> - - <section xml:id='sdo.examples'> - &reftitle.examples; - <para> - The examples below assume an SDO created with the schema - and instance information shown below, using the XML Data Access Service. - </para> - <para> - The instance document below describes a single company, - called 'MegaCorp', which contains a single department, - called 'Advanced Technologies'. - The Advanced Technologies department contains three employees. - The company employeeOfTheMonth is referencing the second employee, - 'Jane Doe'. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<?xml version="1.0" encoding="UTF-8" ?> -<company xmlns="companyNS" name="MegaCorp" - employeeOfTheMonth="E0003"> - <departments name="Advanced Technologies" location="NY" number="123"> - <employees name="John Jones" SN="E0001"/> - <employees name="Jane Doe" SN="E0003"/> - <employees name="Al Smith" SN="E0004" manager="true"/> - </departments> -</company> -]]> - </programlisting> - </para> - <para> The root element of the schema is a company. The company contains departments, and - each department contains employees. Each element has a number of attributes to store - things like name, serial number, and so on. Finally, the company also has an IDREF - attribute which identifies one of the employees as the 'employeeOfTheMonth'. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<xsd:schema - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:sdo="commonj.sdo" - xmlns:sdoxml="commonj.sdo/xml" - xmlns:company="companyNS" - targetNamespace="companyNS"> - <xsd:element name="company" type="company:CompanyType"/> - <xsd:complexType name="CompanyType"> - <xsd:sequence> - <xsd:element name="departments" type="company:DepartmentType" - maxOccurs="unbounded"/> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="employeeOfTheMonth" type="xsd:IDREF" - sdoxml:propertyType="company:EmployeeType"/> - </xsd:complexType> - <xsd:complexType name="DepartmentType"> - <xsd:sequence> - <xsd:element name="employees" type="company:EmployeeType" - maxOccurs="unbounded"/> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="location" type="xsd:string"/> - <xsd:attribute name="number" type="xsd:int"/> - </xsd:complexType> - <xsd:complexType name="EmployeeType"> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="SN" type="xsd:ID"/> - <xsd:attribute name="manager" type="xsd:boolean"/> - </xsd:complexType> -</xsd:schema> -]]> - </programlisting> - </para> - <para>The XML Data Access Service maps the schema to an SDO. Attributes such as "name" - become primitive properties, the sequence of employees becomes a many-valued - containment relationship, and so on. Note that the containment relationships are - expressed as one complex type within another, whereas non-containment references are - expressed in terms of ID and IDREF, with a special - <command>sdoxml:propertyType</command> attribute specifying the type of the - non-containment reference. - </para> - </section> - - <section xml:id="sdo.sample.getset"> - <title>Setting and Getting Property Values</title> - <para> The following examples assume - <command>$company</command> is the root of a tree of data objects created from the - schema and instance document shown above. - </para> - <para> - <example> - <title>Access via property name</title> - <para> - Data object properties can be accessed using the object property - access syntax. The following sets the company name to 'Acme'. - </para> - <programlisting role="php" xml:id="sdo.examples.propname"> -<![CDATA[ -<?php - $company->name = 'Acme'; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Access via property name as array index</title> - <para>We can also access properties using associative array syntax. The simplest - form of this uses the property name as the array index. For example, the following sets - the company name and gets the employeeOfTheMonth. - </para> - <programlisting role="php" xml:id="sdo.examples.simplexpath"> -<![CDATA[ -<?php - $company['name'] = 'UltraCorp'; - $eotm = $company['employeeOfTheMonth']; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Data Object iteration</title> - <para> - We can iterate over the properties of a data object using foreach. - The following iterates over the properties of the employee of the month. - </para> - <programlisting role="php" xml:id="sdo.examples.doiter"> -<![CDATA[ -<?php - $eotm = $company->employeeOfTheMonth; - foreach ($eotm as $name => $value) { - echo "$name: $value\n"; - } -?> -]]> - </programlisting> - <para> - which will output: - </para> - <programlisting xml:id="sdo.examples.doiter-output"> -<![CDATA[ -name: Jane Doe -SN: E0003 -]]> - </programlisting> - <para> - The 'manager' property is not output, because it has not been set. - </para> - </example> - </para> - - <para> - <example> - <title>Access many-valued property by name</title> - <para> Many-valued data object properties can also be accessed using the object - property name syntax. The following gets the list of departments. - </para> - <programlisting role="php" xml:id="sdo.examples.mvpname"> -<![CDATA[ -<?php - $departments = $company->departments; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Many-valued element access</title> - <para> - We can access individual elements of many-valued properties using array - syntax. The following accesses the first department in the company. - </para> - <programlisting role="php" xml:id="sdo.examples.mvaccess"> -<![CDATA[ -<?php - $ad_tech_dept = $company->departments[0]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Many-valued property iteration</title> - <para> - Many-valued properties can also be iterated over using - foreach. The following iterates over the company's departments. - </para> - <programlisting role="php" xml:id="sdo.examples.mvpiter"> -<![CDATA[ -<?php - foreach ($company->departments as $department) { - // ... - } -?> -]]> - </programlisting> - <para> - Each iteration will assign the next department in the - list to the variable <command>$department</command>. - </para> - </example> - </para> - - <para> - <example> - <title>Chained property access</title> - <para> We can chain property references on a single line. - The following sets and gets the name of the first department. - </para> - <programlisting role="php" xml:id="sdo.examples.nestedprop"> -<![CDATA[ -<?php - $company->departments[0]->name = 'Emerging Technologies'; - $dept_name = $company->departments[0]->name; -?> -]]> - </programlisting> - <para>Using the associative array syntax, this is equivalent to</para> - <programlisting role="php" xml:id="sdo.examples.chainarray"> -<![CDATA[ -<?php - $company['departments'][0]['name'] = 'Emerging Technologies'; - $dept_name = $company['departments'][0]['name']; -?> -]]> - </programlisting> - <para> In either case, the dept_name variable is set to 'Emerging Technologies'. - </para> - </example> - </para> - - <para> - <example> - <title>XPath navigation</title> - <para> The associative array index can be an XPath-like expression. Valid - expressions are defined by an augmented sub-set of XPath. - </para> - <para> - Two forms of indexing into many-valued properties are supported. - The first is the standard XPath array syntax with the indexing - starting at one, the second is an SDO extension to XPath with an index - starting at zero. The standard syntax is: - </para> - <programlisting role="php" xml:id="sdo.examples.xpath1nav"> -<![CDATA[ -<?php - $jane_doe = $company["departments[1]/employees[2]"]; -?> -]]> - </programlisting> - <para>and the SDO XPath extension syntax is:</para> - <programlisting role="php" xml:id="sdo.examples.xpath0nav"> -<![CDATA[ -<?php - $jane_doe = $company["departments.0/employees.1"]; -?> -]]> - </programlisting> - <para> - Both these examples get the second employee from the first department. - </para> - </example> - </para> - - <para> - <example> - <title>XPath querying</title> - <para> - We can use XPath to query and identify parts of a data object based - on instance data. The following retrieves the manager from the - 'Advanced Technologies' department. - </para> - <programlisting role="php" xml:id="sdo.examples.xpathquery"> - <![CDATA[ -<?php - $ad_tech_mgr = - $company["departments[name='Advanced Technologies']/employees[manager=true]"]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Creating child data objects</title> - <para> - A data object can be a factory for its child data objects. - A child data object is automatically part of the data graph. - The following add a new employee to the 'Advanced Technologies' - department. - </para> - <programlisting role="php" xml:id="sdo.examples.create"> -<![CDATA[ -<?php - $ad_tech_dept = $company["departments[name='Advanced Technologies']"]; - $new_hire = $ad_tech_dept->createDataObject('employees'); - $new_hire->name = 'John Johnson'; - $new_hire->SN = 'E0005'; - $new_hire->manager = false; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a primitive property</title> - <para> - We can use the <function>isset</function> and - <function>unset</function> functions to test and remove items - from the data object. - </para> - <para> - The following clears the name of the first department. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetprim"> -<![CDATA[ -<?php - unset($company->departments[0]->name); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a data object</title> - <para> - unset can also be used to remove a data object from the tree. - The following example shows John Jones leaving the company. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetdo"> -<![CDATA[ -<?php - unset($company->departments[0]->employees[0]); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a referenced data object</title> - <para> - The following removes the 'employeeOfTheMonth' from the company. - If this were a containment relationship then the - employee would be removed from the company - (probably not a good idea to sack your best employee each month!), - but since this is a non-containment reference, - the employee being referenced will remain in the - department in the company, - but will no longer be accessible via the employeeOfTheMonth property. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetrefdo"> -<![CDATA[ -<?php - if (isset($company->employeeOfTheMonth)) { - unset($company->employeeOfTheMonth); - } -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Access via property index</title> - <para> Data object properties can be accessed via their property index using array - syntax. The property index is the position at which the property's definition - appears in the model (in this case the xml schema). We can see from the schema listing - above that the company name attribute is the second company property (the SDO - interface makes no distinction between XML attributes and elements). The following - sets the company name to 'Acme', with the same result as - <link linkend="sdo.examples.propname">Access via property name</link> - </para> - <programlisting role="php" xml:id="sdo.examples.propindex"> -<![CDATA[ -<?php - $company[1] = 'Acme'; -?> -]]> - </programlisting> - <para> Using the index directly in this way is likely to be fragile. Normally the - property name syntax should be preferred, but the property index may be required - in special cases. - </para> - </example> - </para> - - </section> - - <section xml:id="sdo.sample.sequence"> - <title>Working with Sequenced Data Objects</title> - <para> - Sequenced data objects are SDOs which can track property - ordering across the properties of a data object. They can also - contain unstructured text elements (text element which do not - belong to any of the SDO's properties). Sequenced data objects are - useful for working with XML documents which allow unstructured text (i.e. - mixed=true) or if the elements can be interleaved ( - <![CDATA[<A/><B/><A/>]]>). This can occur for example when - the schema defines maxOccurs>1 on a - element which is a complexType with a choice order indicator. - </para> - <para> - The examples below assume an SDO created with the following schema - and instance information, using the XML Data Access Service. - </para> - <para> - The schema below describes the format of a letter. The letter can - optionally contain three properties; date, firstName, and lastName. - The schema states <command>mixed="true"</command> which means that - unstructured text can be interspersed between the three properties. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:letter="http://letterSchema" - targetNamespace="http://letterSchema"> - <xsd:element name="letters" type="letter:FormLetter"/> - <xsd:complexType name="FormLetter" mixed="true"> - <xsd:sequence> - <xsd:element name="date" minOccurs="0" type="xsd:string"/> - <xsd:element name="firstName" minOccurs="0" type="xsd:string"/> - <xsd:element name="lastName" minOccurs="0" type="xsd:string"/> - </xsd:sequence> - </xsd:complexType> -</xsd:schema> - ]]> - </programlisting> - </para> - - <para> - The following is an instance letter document. It contains the - three letter properties; date, firstName and lastName, and has - unstructured text elements for the address and letter body. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<letter:letters xmlns:letter="http://letterSchema"> - <date>March 1, 2005</date> - Mutual of Omaha - Wild Kingdom, USA - Dear - <firstName>Casy</firstName> - <lastName>Crocodile</lastName> - Please buy more shark repellent. - Your premium is past due. -</letter:letters> - ]]> - </programlisting> - </para> - <para> - When loaded, the letter data object will have the sequence and - property indices shown in the table below: - <informaltable> - <tgroup cols='3'> - <thead> - <row> - <entry>Sequence Index</entry> - <entry>Property Index:Name</entry> - <entry>Value</entry> - </row> - </thead> - <tbody> - <row> - <entry>0</entry> - <entry>0:date</entry> - <entry>March 1, 2005</entry> - </row> - <row> - <entry>1</entry> - <entry>-</entry> - <entry>Mutual of Omaha</entry> - </row> - <row> - <entry>2</entry> - <entry>-</entry> - <entry>Wild Kingdom, USA</entry> - </row> - <row> - <entry>3</entry> - <entry>-</entry> - <entry>Dear</entry> - </row> - <row> - <entry>4</entry> - <entry>1:firstName</entry> - <entry>Casy</entry> - </row> - <row> - <entry>5</entry> - <entry>2:lastName</entry> - <entry>Crocodile</entry> - </row> - <row> - <entry>6</entry> - <entry>-</entry> - <entry>Please buy more shark repellent.</entry> - </row> - <row> - <entry>7</entry> - <entry>-</entry> - <entry>Your premium is past due.</entry> - </row> - </tbody> - </tgroup> - </informaltable> - </para> - - <para> - To ensure sequence indices are maintained, sequenced data objects - should be manipulated through the SDO_Sequence interface. - This allows the data object's instance data to be manipulated - in terms of the sequence index as opposed to the property index - (shown in the table above). - The following examples assume the letter instance has been - loaded into a data object referenced by the variable - <command>$letter</command>. - <example> - <title>Getting the SDO_Sequence interface</title> - <para> - We obtain a data object's sequence using the - <function>getSequence</function> - method. The follow gets the - sequence for the letter data object. - </para> - <programlisting role="php" xml:id="sdo.examples.seqinterface"> -<![CDATA[ -<?php - $letter_seq = $letter->getSequence(); -?> -]]> - </programlisting> - </example> - </para> - <para> - All subsequent examples assume that the - <command>$letter_seq</command> - variable has been assigned the sequence for the letter data object. - </para> - - <para> - <example> - <title>Get/set sequence values</title> - <para> - We can get and set individual values (including unstructured text) - using the sequence index. - The following sets the firstName to 'Snappy' and gets the last - sequence values (the unstructured text, 'Your premium is past due.'). - </para> - <programlisting role="php" xml:id="sdo.examples.getsetseq"> -<![CDATA[ -<?php - $letter_seq[4] = 'Snappy'; - $text = $letter_seq[count($letter_seq) - 1]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Sequence iteration</title> - <para> - We can iterate through the individual sequence values using foreach. - The following runs through the individual values in sequence order. - </para> - <programlisting role="php" xml:id="sdo.examples.seqiter"> -<![CDATA[ -<?php - foreach ($letter->getSequence() as $value) { - // ... - } -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Sequence versus Data Object</title> - <para> - Setting values through the data object interface may result in the - value not being part of the sequence. A value set through the data - object will only be accessible through the sequence if the property was - already part of the sequence. The following example sets the - lastName through the data object and gets it through the sequence. - This is fine because lastName already exists in the sequence. If - it had not previously been set, then lastName would be set to - 'Smith', but would not be part of the sequence. - </para> - <programlisting role="php" xml:id="sdo.examples.seqvsdo"> -<![CDATA[ -<?php - $letter[2] = 'Smith'; - $last_name = $letter_seq[5]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Adding to a sequence</title> - <para> - We can add new values to a sequence using the - <link linkend='function.SDO-Sequence-insert'><function>SDO_Sequence::insert</function></link> - method. The following examples assume that the 'firstName' and - 'lastName' properties are initially unset. - </para> - <programlisting role="php" xml:id="sdo.examples.seqadd"> -<![CDATA[ -<?php - // Append a firstName value to the sequence - // value: 'Smith' - // sequence index: NULL (append) - // propertyIdentifier: 1 (firtName property index) - $letter_seq->insert('Smith', NULL, 1); - - // Append a lastName value to the sequence - // value: 'Jones' - // sequence index: NULL (append) - // propertyIdentifier: 'lastName' (lastName property name) - $letter_seq->insert('Jones', NULL, 'lastName'); - - // Append unstructured text - // value: 'Cancel Subscription.' - // sequence index: absent (append) - // propertyIdentifier: absent (unstructured text) - $letter_seq->insert('Cancel Subscription.'); - - // Insert new unstructured text. Subsequent sequence values - // are shifted up. - // value: 'Care of:' - // sequence index: 1 (insert as second element) - // propertyIdentifier: absent (unstructured text) - $letter_seq->insert('Care of:', 1); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Removing from a sequence</title> - <para> - We can use the <function>isset</function> and - <function>unset</function> functions to test and remove items - from the sequence (Note: <function>unset</function> currently - leaves the values in the data object, but this behaviour is - likely to change to also remove the data from the data object). - A sequence behaves like a contiguous list; therefore, removing - items from the middle will shift entries at higher indices - down. The following example tests to see if the first sequence - element is set and unsets it if is. - </para> - <programlisting role="php" xml:id="sdo.examples.seqremove"> -<![CDATA[ -<?php - if (isset($letter_seq[0])) { - unset($letter_seq[0]); - } -?> -]]> - </programlisting> - </example> - </para> - - </section> - - - <section xml:id="sdo.sample.reflection"> - <title>Reflecting on Service Data Objects</title> - <para> - SDOs have a knowledge of the structure they have been created to - represent (the model). For example, a Company SDO created using - <link linkend="sdo.examples">the Company XML schema</link> above - would only be permitted to contain DepartmentType data objects - which in turn could only contain EmployeeType data objects. - </para> - <para> - Sometimes it is useful to be able to access this model information at - runtime. For example, this could be used to automatically generate - a user interface for populating a data object. The model information - is accessed using reflection. - </para> - - <para> - <example> - <title>Reflecting on a Data Object</title> - <para> - The following example shows how we can reflect on an empty Employee - data object. - </para> - <programlisting role="php" xml:id="sdo.examples.reflection"> -<![CDATA[ -<?php - // Create the employee data object (e.g. from an XML Data Access Service) - $employee = ...; - $reflection = new SDO_Model_ReflectionDataObject($employee); - print($reflection); -?> -]]> - </programlisting> - &example.outputs; - - <screen> -<![CDATA[ -object(SDO_Model_ReflectionDataObject)#4 { - ROOT OBJECT - Type { -companyNS:EmployeeType[3] { commonj.sdo:String $name; -commonj.sdo:String $SN; commonj.sdo:Boolean $manager; } } -]]> - </screen> - <para> - Using print on the SDO_Model_ReflectionDataObject writes out the data - object's model. We can see from the output how the type - companyNS:EmployeeType has three properties and we can see the names - of the properties along with their types. Note, the primitive types - are listed as SDO types (e.g. commonj.sdo namespace, String type). - It is worth noting that this is the SDO model and when these are - surfaced to an application they can be treated as the PHP equivalent - types (e.g. string and boolean). - </para> - </example> - </para> - - <para> - <example> - <title>Accessing the type information</title> - <para> - We can query the type information of a data object using reflection. - The following example checks the type corresponds to a data object - rather than a primitive and then iterates through the properties of - the type, writing out the name of each property ($type and $property - are SDO_Model_Type and SDO_Model_Property objects, respectively). - </para> - <programlisting role="php" xml:id="sdo.examples.reflection.type"> -<![CDATA[ -<?php - // Create the employee data object (e.g. from an XML Data Access Service) - $employee = ...; - $reflection = new SDO_Model_ReflectionDataObject($employee); - $type = $reflection->getType(); - if (! $type->isDataType()) { - foreach ($type->getProperties() as $property) { - print $property->getName() . "\n"; - } - } -?> -]]> - </programlisting> - &example.outputs; - <screen> -<![CDATA[ -name -SN -manager -]]> - </screen> - </example> - </para> - - </section> - - - - + <!-- FIXME: Everything below should be removed and follow our OO skeletons --> <!-- class definition section --> <section xml:id='sdo.classes'> @@ -1718,8 +645,6 @@ </section> </section> - &reference.sdo.constants; - </partintro> &reference.sdo.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/sdodasrel/constants.xml diff -u phpdoc/en/reference/sdodasrel/constants.xml:1.3 phpdoc/en/reference/sdodasrel/constants.xml:1.3.2.1 --- phpdoc/en/reference/sdodasrel/constants.xml:1.3 Wed Jun 20 22:25:19 2007 +++ phpdoc/en/reference/sdodasrel/constants.xml Fri Dec 7 14:24:26 2007 @@ -1,14 +1,13 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.3 $ --> -<!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> -<section xml:id="sdodasrel.constants" xmlns="http://docbook.org/ns/docbook"> - <!-- &reftitle.constants; - &extension.constants; - --> +<!-- $Revision: 1.3.2.1 $ --> + +<appendix xml:id="sdodasrel.constants" xmlns="http://docbook.org/ns/docbook"> + &reftitle.constants; + &extension.constants; <para> The Relational DAS introduces no predefined constants. </para> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/reference.xml?r1=1.21.2.2&r2=1.21.2.3&diff_format=u Index: phpdoc/en/reference/sdodasrel/reference.xml diff -u phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.2 phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.3 --- phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.2 Fri Nov 2 12:13:28 2007 +++ phpdoc/en/reference/sdodasrel/reference.xml Fri Dec 7 14:24:26 2007 @@ -1,1442 +1,13 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.21.2.2 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: pecl --> -<!-- State: experimental --> +<!-- $Revision: 1.21.2.3 $ --> <reference xml:id="ref.sdo.das.rel" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>SDO Relational Data Access Service Functions</title> <titleabbrev>SDO-DAS-Relational</titleabbrev> <partintro> - <section xml:id="sdo.das.rel.intro"> - &reftitle.intro; - <para> - <!-- This warns that the extension is experimental --> - &warn.experimental; - </para> - <para> - In order to use the Relational Data Access Service for - Service Data Objects, - you will need to understand some of the concepts behind SDO: - the data graph, the data object, the disconnected way of working, - the change summary, XPath and property expressions, and so on. - If you are not familiar with these ideas, you might want to look first at - <link linkend='ref.sdo'>the section on SDO</link>. - In addition, the Relational DAS makes use of the PDO extension to - isolate itself from specifics of different back-end relational databases. - In order to use the Relational DAS you will need to be able to - create and pass a PDO database connection; - for this reason you might also want to take a look at - <link linkend='ref.pdo'>the section on PDO</link>. - </para> - - <para> - The job of the Relational DAS is to move data between the application - and a relational database. In order to do this it needs to be told - the mapping between the database entities - - tables, columns, primary keys and foreign keys - - and the elements of the SDO model - - types, properties, containment relationships and so on. - You specify this information as metadata when you - construct the Relational DAS. - </para> - - <procedure xml:id='overview'> - <title>Overview of Operation</title> - <step> - <para> - The first step is to call the Relational DAS's constructor, - passing the metadata that defines the mapping between - database and SDO model. - There are examples of this below. - </para> - </step> - - <step> - <para> - The next step might be to call the - <function>executeQuery</function> - or - <function>executePreparedQuery</function> - methods on the Relational DAS, passing either a literal SQL statement - for the DAS to prepare and execute, or a prepared statement with - placeholders and a list of values to be inserted. - You may also need to specify a small amount of metadata - about the query itself, so that the Relational DAS knows - exactly what columns will be returned from the database and - in what order. You will also need to pass a PDO database connection. - </para> - - <para> - The return value from - <function>executeQuery</function> - or - <function>executePreparedQuery</function> - is a normalised data graph containing all the data from the result set. - For a query that returns data obtained from a number of tables, - this graph will contain a number of data objects, - linked by SDO containment relationships. - There may also be SDO non-containment references within the data. - </para> - - <para> - Once the query has been executed and the data graph constructed, - there is no need for either that instance of the the Relational DAS or - the database connection. There are no locks held on the database. - Both the Relational DAS and the PDO database connection can be - garbage collected. - </para> - </step> - <step> - <para> - Quite possibly the data in the data graph will go through - a number of modifications. The data graph can be serialised - into the PHP session and so may have a lifetime beyond just - one client-server interaction. Data objects can be created - and added to the graph, the data objects already in the graph - can be deleted, and data objects in the graph can be modified. - </para> - </step> - <step> - <para> - Finally, the changes made to the data graph can be applied - back to the database using the - <function>applyChanges</function> - method of the Relational DAS. For this, another instance - of the Relational DAS must be constructed, using the - same metadata, and another connection to the database obtained. - The connection and the data graph are passed to - <function>applyChanges</function>. - At this point the Relational DAS examines the change summary - and generates the necessary INSERT, UPDATE and DELETE SQL statements - to apply the changes. Any UPDATE and DELETE statements are qualified - with the original values of the data so that should the data have - changed in the database in the meantime this will be detected. - Assuming no such collisions have occurred the changes will be - committed to the database. The application can then continue to work - with the data graph, make more changes and apply them, or can discard - it. - </para> - </step> - </procedure> - <para> - There are other ways of working with the data in the database: - it is possible to just create data objects and write them to the - database without a preliminary call to - <function>executeQuery</function>, - for example. This scenario and others are explored in the - <link linkend="sdo.das.rel.examples">Examples</link> - section below. - </para> - </section> <!-- intro --> - - <section xml:id="sdo.das.rel.installation"> - &reftitle.install; - <para> - The installation instructions for all the SDO components - are in the SDO - <link linkend="sdo.installation">install</link> - section of the SDO documentation. - </para> - <para> - In any case, the essential facts are that - the Relational DAS is written in PHP and it - should be placed somewhere on the PHP - <link linkend="ini.include-path">include_path</link> - . - </para> - - <para> - Your application will of course need to include the Relational DAS - with a statement like this: - <programlisting role="php"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -?> -]]> - </programlisting> - </para> - </section> - - <section xml:id="sdo.das.rel.requirements"> - &reftitle.required; - <para> - The Relational DAS requires that the SDO extension be installed. - The SDO extension requires a version of PHP 5.1, and the - Relational DAS requires a recent version that contains - an important fix for PDO. The most up-to-date information about - required levels of PHP should be found in the changelog for the - package on PECL. At the time of writing, though, the Relational - DAS requires the most recent beta level of PHP 5.1, that is - PHP 5.1.0. - </para> - <para> - The Relational DAS uses PDO to access the relational database, - and so should run with a variety of different relational databases. - At the time of writing it has been tested in the following configurations - <itemizedlist> - <listitem> - <para> - MySQL 4.1.14, on Windows. - The Relational DAS operates correctly with the php_pdo_mysql - driver that comes with the pre-built binaries for PHP 5.1.0. - </para> - </listitem> - <listitem> - <para> - MySQL 4.1.13, on Linux. It is necessary to have the most up-to-date - PDO driver for MySQL, which comes built in to PHP 5.1.0. - It may be necessary to uninstall the usual driver that would have - come from PECL using - <command>pear uninstall pdo_mysql</command> - . You will need to configure PHP with the - <command>--with-pdo-mysql</command> option. - </para> - </listitem> - <listitem> - <para> - DB2 8.2 Personal Edition, on Windows. - The Relational DAS operates correctly with the - php_pdo_odbc driver that comes with the pre-built binaries for - PHP 5.1.0. - </para> - </listitem> - <listitem> - <para> - DB2 8.2 Personal Developer's Edition, on Linux. - The Developer's Edition is needed because it - contains the include files needed when PHP is configured - and built. You will need to configure PHP with the - <command>--with-pdo-odbc=ibm-db2</command> option. - </para> - </listitem> - </itemizedlist> - </para> - - <para> - The Relational DAS applies changes to the database within - a user-delimited transaction: that is, it issues a call to - <function>PDO::beginTransaction</function> - before beginning to apply changes, and - <function>PDO::commit</function> - or - <function>PDO::rollback</function> - on completion. - Whichever database is chosen, the database and the PDO driver - for the database must support these calls. - </para> - </section> - - <section xml:id="sdo.das.rel.limitations"> - <title>Limitations</title> - <para> - There are the following limitations in the current release of the - Relational DAS: - <itemizedlist> - <listitem> - <para> - No support for nulls. There is no support for SQL NULL type. - It is not legal to assign PHP NULL to a data object property - and the Relational DAS will not write that back as a NULL to the - database. If nulls are found in the database on a query, - the property will remain unset. - </para> - </listitem> - <listitem> - <para> - Only two types of SDO relationship. The metadata described below - allows the Relational DAS to model just two types of SDO relationship: - multi-valued containment relationships and single-valued - non-containment references. In SDO, whether a property describes a - single- or multi-valued relationship, and whether it is containment - or non-containment, are independent. The full range of possibilities - that SDO allows cannot all be defined. There may be relationships - that it would be useful to model but which the current implementation - cannot manage. - One example is a single-valued containment relationship. - </para> - </listitem> - <listitem> - <para> - No support for the full range of SDO data types. The Relational - DAS defines all primitive properties in the SDO model as being - of type string. SDO defines a richer set of types containing various - integer, float, boolean and data and time types. String is adequate - for the purposes of the Relational DAS since the combination of PHP, - PDO and the database will ensure that values passed as strings - will be converted to the proper type before being put in the database. - This does affect some scenarios in which the Relational DAS has - to work with a data graph that has come from or will go to a - different DAS. - </para> - </listitem> - <listitem> - <para> - Only one foreign key per table. - The metadata only provides the means to specify one foreign key - per table. This foreign key may be mapped to one of the two types of - SDO relationship supported. Obviously there are some scenarios - that cannot be described under this limitation - it is not possible - to have two non-containment references from one table to another - for example. - </para> - </listitem> - </itemizedlist> - </para> - </section> - - <section xml:id='sdo.das.rel.examples'> - &reftitle.examples; - <para> - This section illustrates how the Relational DAS can be used to create, - retrieve, update and delete data in a relational database. - Many of the examples are illustrated with a three-table database that - contains companies, departments within those companies, and employees - that work in those departments. This example is used in a number of - places within the SDO literature. See the examples section of the - <link xlink:href='&url.ibm.sdo.spec;'>Service Data Objects specification</link> - or the - <link linkend="sdo.examples">Examples</link> - section of the documentation for the SDO extension. - </para> - - <para> - The Relational DAS is constructed with metadata that defines the - relational database and how it should be mapped to SDO. - The long section that follows describes this metadata and how to - construct the Relational DAS. The examples that follow it all assume that - this metadata is in an included php file. - </para> - - <para> - The examples below and others can all be found in the - <filename>Scenarios</filename> - directory in the Relational DAS package. - </para> - - <para> - The Relational DAS throws exceptions in the event that it finds errors - in the metadata or errors when executing SQL statements against the - database. For brevity the examples below all omit the use of try/catch - blocks around the calls to the Relational DAS. - </para> - - <para> - These examples all differ from the expected use of SDO in two - important respects. - </para> - <para> - First, they show all interactions with the database completed within - one script. In this respect these scenarios are not realistic but are - chosen to illustrate just the use of the Relational DAS. - It is expected that interactions with the database will be separated - in time and the data graph serialised and deserialised into the PHP - session one or more times as the application interacts with an end user. - </para> - <para> - Second, all queries executed against the database use hard-coded - queries with no variables substituted. In this case it is safe to - use the simple - <function>executeQuery</function> - call, and this is what the examples illustrate. - In practice, though, it is unlikely that the SQL statement is known - entirely ahead of time. In order to allow variables to be safely - substituted into the SQL queries, without running the risk of - injecting SQL with unknown effects, it is safer to use the - <function>executePreparedQuery</function> - which takes a prepared SQL statement containing placeholders - and a list of values to be substituted. - </para> - - <section xml:id='sdo.das.rel.metadata'> - <title>Specifying the metadata</title> - <para> - This first long section describes in detail how the metadata describing - the database and the required SDO model is supplied to the - Relational DAS. - </para> - <para> - When the constructor for the Relational DAS is invoked, it needs to be - passed several pieces of information. The bulk of the information, - passed as an associative array in the first argument to the constructor, - tells the Relational DAS what it needs to know about the relational - database. It describes the names of the tables, columns, primary keys - and foreign keys. It should be fairly easy to understand what is - required, and once written it can be placed in a php file and included - when needed. The remainder of the information, passed in the second - and third arguments to the constructor, tells the Relational DAS what - it needs to know about the relationships between objects and the shape - of the data graph; it ultimately determines how the data from the - database is to be normalised into a graph. - </para> - - <section xml:id='sdo.das.rel.metadata.database'> - <title>Database metadata</title> - <para> - The first argument to the constructor describes the target - relational database. - </para> - - <para> - Each table is described by an associative array with up to four keys. - <informaltable> - <tgroup cols='2'> - <thead> - <row> - <entry>Key</entry> - <entry>Value</entry> - </row> - </thead> - <tbody> - <row> - <entry>name</entry> - <entry>The name of the table.</entry> - </row> - <row> - <entry>columns</entry> - <entry> - An array listing the names of the columns, in any order. - </entry> - </row> - <row> - <entry>PK</entry> - <entry>The name of the column containing the primary key.</entry> - </row> - <row> - <entry>FK</entry> - <entry>An array with two entries, 'from' and 'to', which define - a column containing a foreign key, and a table to which the foreign - key points. If there are no foreign keys in the table then the - 'FK' entry does not need to be specified. Only one foreign key - can be specified. Only a foreign key pointing to the primary key - of a table can be specified. - </entry> - </row> - </tbody> - </tgroup> - </informaltable> - </para> - - <programlisting role="php"> -<![CDATA[ -<?php -/***************************************************************** -* METADATA DEFINING THE DATABASE -******************************************************************/ -$company_table = array ( - 'name' => 'company', - 'columns' => array('id', 'name', 'employee_of_the_month'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'employee_of_the_month', - 'to' => 'employee', - ), - ); -$department_table = array ( - 'name' => 'department', - 'columns' => array('id', 'name', 'location', 'number', 'co_id'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'co_id', - 'to' => 'company', - ) - ); -$employee_table = array ( - 'name' => 'employee', - 'columns' => array('id', 'name', 'SN', 'manager', 'dept_id'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'dept_id', - 'to' => 'department', - ) - ); -$database_metadata = array($company_table, $department_table, $employee_table); -?> -]]> - </programlisting> - - <para> - This metadata corresponds to a relational database that might have - been defined to MySQL as: - </para> - <programlisting role="sql"> -<![CDATA[ - create table company ( - id integer auto_increment, - name char(20), - employee_of_the_month integer, - primary key(id) - ); - create table department ( - id integer auto_increment, - name char(20), - location char(10), - number integer(3), - co_id integer, - primary key(id) - ); - create table employee ( - id integer auto_increment, - name char(20), - SN char(4), - manager tinyint(1), - dept_id integer, - primary key(id) - ); -]]> - </programlisting> - <para> - or to DB2 as: - </para> - <programlisting role="sql"> -<![CDATA[ -create table company ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - employee_of_the_month integer, \ - primary key(id) ) -create table department ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - location varchar(10), \ - number integer, \ - co_id integer, \ - primary key(id) ) -create table employee ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - SN char(4), \ - manager smallint, \ - dept_id integer, \ - primary key(id) ) -]]> - </programlisting> - - <para> - Note that although in this example there are no foreign keys specified - to the database and so the database is not expected to enforce - referential integrity, the intention behind the - <varname>co_id</varname> - column on the department table and the - <varname>dept_id</varname> - column on the employee table is they should contain the primary key - of their containing company or department record, respectively. - So these two columns are acting as foreign keys. - </para> - - <para> - There is a third foreign key in this example, that from the - <varname>employee_of_the_month</varname> - column of the company record to a single row of the employee table. - Note the difference in intent between this foreign key and the other - two. The - <varname>employee_of_the_month</varname> - column represents a single-valued relationship: there can be only - one employee of the month for a given company. - The - <varname>co_id</varname> - and - <varname>dept_id</varname> - columns represent multi-valued relationships: a company can contain - many departments and a department can contain many employees. - This distinction will become evident when the remainder of the metadata - picks out the company-department and department-employee relationships - as containment relationships. - </para> - - <para> - There are a few simple rules to be followed when constructing the - database metadata: - </para> - - <itemizedlist> - <listitem> - <para> - All tables must have primary keys, and the primary keys must be - specified in the metadata. Without primary keys it is not possible - to keep track of object identities. As you can see from the SQL - statements that create the tables, primary keys can be - auto-generated, that is, generated and assigned by the database when - a record is inserted. In this case the auto-generated primary key - is obtained from the database and inserted into the data object - immediately after the row is inserted into the database. - </para> - </listitem> - - <listitem> - <para> - It is not necessary to specify in the metadata all the columns - that exist in the database, only those that will be used. - For example, if the company table had another column that the - application did not want to access with SDO, this need not be - specified in the metadata. On the other hand it would have done - no harm to specify it: if specified in the metadata but never - retrieved, or assigned to by the application, then the unused column - will not affect anything. - </para> - </listitem> - - <listitem> - <para> - In the database metadata note that the foreign key definitions - identify not the destination column in the table which is pointed - to, but the table name itself. Strictly, the relational model - permits the destination of a foreign key to be a non-primary key. - Only foreign keys that point to a primary key are useful for - constructing the SDO model, so the metadata specifies the table name. - It is understood that the foreign key points to the primary key of - the given table. - </para> - </listitem> - </itemizedlist> - - <para> - Given these rules, and given the SQL statements that define the - database, the database metadata should be easy to construct. - </para> - - <section xml:id='sdo.das.rel.metadata.database.model'> - <title>What the Relational DAS does with the metadata</title> - <para> - The Relational DAS uses the database metadata to form most of the - SDO model. For each table in the database metadata, an SDO type - is defined. Each column which can represent a primitive value - (columns which are not defined as foreign keys) are added - as properties to the SDO type. - </para> - <para> - All primitive properties are given a type of string in the SDO model, - regardless of their SQL type. When writing values back to the - database the Relational DAS will create SQL statements that treat - the values as strings, and the database will convert them to the - appropriate type. - </para> - - <para> - Foreign keys are interpreted in one of two ways, depending on the - metadata in the third argument to the constructor that defines - the SDO containment relationships. - A discussion of this is therefore deferred until the section on - <link linkend="sdo.das.rel.metadata.crels"> - SDO containment relationships - </link> - below. - </para> - </section> - </section> - - <section xml:id='sdo.das.rel.metadata.approottype'> - <title>Specifying the application root type</title> - <para> - The second argument to the constructor is the application root type. - The true root of each data graph is an object of a special root type - and all application data objects come somewhere below that. Of the - various application types in the SDO model, one has to be the - application type immediately below the root of the data graph. - If there is only one table in the database metadata, the application - root type can be inferred, and this argument can be omitted. - </para> - </section> - - <section xml:id='sdo.das.rel.metadata.crels'> - <title>Specifying the SDO containment relationships</title> - - <para> - The third argument to the constructor defines how the types in the - model are to be linked together to form a graph. It identifies the - parent-child relationships between the types which collectively form a - graph. The relationships need to be supported by foreign keys to be - found in the data, in a way shortly to be described. - </para> - - <para> - The metadata is an array containing one or more associative arrays, - each of which identifies a parent and a child. The example below shows - a parent-child relationship from company to department, and another - from department to employee. Each of these will become an SDO property - defining a multi-valued containment relationship in the SDO model. - - </para> - <programlisting role="php"> -<![CDATA[ -<?php -$department_containment = array( 'parent' => 'company', 'child' => 'department'); -$employee_containment = array( 'parent' => 'department', 'child' => 'employee'); - -$SDO_containment_metadata = array($department_containment, $employee_containment); -?> -]]> - </programlisting> - - <para> - Foreign keys in the database metadata are interpreted as properties - with either multi-valued containment relationships or single-valued - non-containment references, depending on whether they have a - corresponding SDO containment relationship specified in the metadata. - In the example here, the foreign keys from department to company (the - <varname>co_id</varname> - column in the department table) - and from employee to department (the - <varname>dept_id</varname> - column in the employee table) are interpreted as supporting the - SDO containment relationships. - Each containment relationship mentioned in the SDO containment relationships - metadata must have a corresponding foreign key present in the - database and defined in the database metadata. The values of the - foreign key columns for containment relationships do not appear in the - data objects, instead each is represented by a containment relationship - from the parent to the child. So the - <varname>co_id</varname> - column in the department row in the database, for example, does not - appear as a property on the department type, but instead as a - containment relationship called - <varname>department</varname> - on the company type. - Note that the foreign key and the parent-child relationship appear to - have opposite senses: the foreign key points from the department to - the company, but the parent-child relationship points from company to - department. - </para> - - <para> - The third foreign key in this example, the - <varname>employee_of_the_month</varname> - , - is handled differently. - This is not mentioned in the SDO containment relationships metadata. - As a consequence this is interpreted in the second way: it becomes - a single-valued non-containment reference on the company object, to - which can be assigned references to SDO data objects of the employee - type. It does appear as a property on the company type. The way to - assign a value to it in the SDO data graph is to have a graph that - contains an employee object through the containment relationships, and - to assign the object to it. This is illustrated in the later examples - below. - </para> - </section> - </section> <!--specifying the metadata --> - - <section xml:id='sdo.das.rel.examples.one-table'> - <title>One-table examples</title> - <para> - The following set of examples all use the Relational DAS to work with - a data graph containing just one application data object, a single - company and the data just to be found the company table. These examples - do not exercise the power of SDO or the Relational DAS and of course - the same result could be achieved more economically with direct SQL - statements but they are intended to illustrate how to work with the - Relational DAS. - </para> - - <para> - For this very simple scenario it would be possible to simplify the - database metadata to include just the company table - if that were done - the second and third arguments to the constructor and the column - specifier used in the query example would become optional. - </para> - - <para> - <example> - <title>Creating a data object</title> - <para> - The simplest example is that of creating a single data object and - writing it to the database. In this example a single company object - is created, its name is set to 'Acme', and the Relational DAS is - called to write the changes to the database. The company name is - set here using the property name method. See the - <link linkend="sdo.examples">Examples</link> - section on the SDO extension for other ways of accessing the - properties of an object. - </para> - - <para> - Data objects can only be created when you have a data object to - start with, however. It is for that reason that the first call - to the Relational DAS here is to obtain a root object. This is - in effect how to ask for an empty data graph - the special root - object is the true root of the tree. The company data object is - then created with a call to - <function>createDataObject</function> - on the root object. This creates the company data object and inserts - it in the graph by inserting into a multi-valued containment property - on the root object called 'company'. - </para> - <para> - When the Relational DAS is called to apply the changes a simple - insert statement 'INSERT INTO company (name) VALUES ("Acme");' - will be constructed and executed. The auto-generated primary key - will be set into the data object and the change summary will be reset, - so that it would be possible to continue working with the same data - object, modify it, and apply the newer changes a second time. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Obtain a root object and create a company object underneath. - * Make a simple change to the data object. - ***************************************************************/ -$root = $das -> createRootDataObject(); -$acme = $root -> createDataObject('company'); - -$acme->name = "Acme"; - -/************************************************************** - * Get a database connection and write the object to the database - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das -> applyChanges($dbh, $root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Retrieving a data object</title> - <para> - In this example a single data object is retrieved from the database - - or possibly more than one if there is more than one company - called 'Acme'. For each company returned, the - <varname>name</varname> - and - <varname>id</varname> - properties are echoed. - </para> - <para> - In this example the third argument to - <function>executeQuery</function>, - the column specifier is needed as there are other tables in the - metadata with column names of - <varname>name</varname> - and - <varname>id</varname>. - If there were no possible ambiguity it could be omitted. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-R"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme"', - array('company.name', 'company.id') ); - -/************************************************************** - * Echo name and id - ***************************************************************/ -foreach ($root['company'] as $company) { - echo "Company obtained from the database has name = " . - $company['name'] . " and id " . $company['id'] . "\n"; -} -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Updating a data object</title> - <para> - This example combines the previous two, in the sense that in order - to be updated the object must first be retrieved. The application - code reverses the company name (so 'Acme' becomes 'emcA') and then the - changes are written back to the database in the same way that they - were when the object was created. Because the query searches for - the name both ways round the program can be run repeatedly to find - the company and reverse its name each time. - </para> - <para> - In this example the same instance of the Relational DAS is reused - for the - <function>applyChanges</function>, - as is the PDO database handle. This is quite alright; it also - alright to allow the previous instances to be garbage collected - and to obtain new instances. No state data regarding the graph - is held the Relational DAS once it has returned a data graph to - the application. All necessary data is either within the graph itself, - or can be reconstructed from the metadata. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme" or name="emcA"', - array('company.name', 'company.id') ); - -/************************************************************** - * Alter the name of just the first company - ***************************************************************/ -$company = $root['company'][0]; -echo "obtained a company with name of " . $company->name . "\n"; -$company->name = strrev($company->name); - -/************************************************************** - * Write the change back - ***************************************************************/ -$das->applyChanges($dbh,$root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Deleting a data object</title> - <para> - Any companies called 'Acme' or its reverse 'emcA' are retrieved. - They are then all deleted from the graph with unset. - </para> - - <para> - In this example they are all deleted in one go by unsetting the - containing property (the property defining the containment - relationship). It is also possible to delete them individually. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme" or name="emcA"', - array('company.name', 'company.id') ); - -/************************************************************** - * Delete any companies found from the data graph - ***************************************************************/ -unset($root['company']); - -/************************************************************** - * Write the change(s) back - ***************************************************************/ -$das->applyChanges($dbh,$root); -?> -]]> - </programlisting> - </example> - </para> - - </section> <!-- one-table --> - - <section xml:id='sdo.das.rel.examples.two-table'> - <title>Two-table examples</title> - <para> - The following set of examples all use two tables from the company - database: the company and department tables. These examples exercise - more of the function of the Relational DAS. - </para> - <para> - In this series of examples a company and department are created, - retrieved, updated, and finally deleted. This illustrates the - lifecycle for a data graph containing more than one object. Note that - this example clears out the company and department tables at the start - so that the exact results of the queries can be known. - </para> - <para> - You can find these examples combined into one script called - <filename>1cd-CRUD</filename> - in the - <filename>Scenarios</filename> - directory in the Relational DAS package. - </para> - - <para> - <example> - <title>One company, one department - Create</title> - <para> - As in the earlier example of creating just one company data object, - the first action after constructing the Relational DAS is to call - <function>createRootDataObject</function> - to obtain the special root object of the otherwise empty data graph. - The company object is then created as a child of the root object, - and the department object as a child of the company object. - </para> - <para> - When it comes to applying the changes, the Relational DAS has to - perform special processing to maintain the foreign keys that support - the containment relationships, especially if auto-generated primary - keys are involved. In this example, the relationship between the - auto-generated primary key - <varname>id</varname> - in the company table and the - <varname>co_id</varname> - column in the department table must be maintained. When inserting a - company and department for the first time the Relational DAS has to - first insert the company row, then call PDO's - <function>getLastInsertId</function> - method to obtain the auto-generated primary key, then add that as - the value of the - <varname>co_id</varname> - column when inserting the department row. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* -* Empty out the two tables -*************************************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$pdo_stmt = $dbh->prepare('DELETE FROM COMPANY;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM DEPARTMENT;'); -$rows_affected = $pdo_stmt->execute(); - -/************************************************************** -* Create a company with name Acme and one department, the Shoe department -***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das -> createRootDataObject(); - -$acme = $root -> createDataObject('company'); -$acme -> name = "Acme"; - -$shoe = $acme->createDataObject('department'); -$shoe->name = 'Shoe'; - -$das -> applyChanges($dbh, $root); - -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, one department - Retrieve and Update</title> - - <para> - In this case the SQL query passed to - <function>executeQuery</function> - performs an inner join to join the data from the company - and department tables. Primary keys for both the company and - department tables must be included in the query. The result set - is re-normalised to form a normalised data graph. Note that a - column specifier is passed as the third argument to the - <function>executeQuery</function> - call enabling the Relational DAS to know which column is which in - the result set. - </para> - <para> - Note that the - <varname>co_id</varname> - column although used in the query is not needed in the result set. - In order to understand what the Relational DAS is doing when it builds - the data graph it may be helpful to visualise what the result set - looks like. Although the data in the database is normalised, so that - multiple department rows can point through their foreign key to one - company row, the data in the result set is non-normalised: that is, - if there is one company and multiple departments, the values for the - company are repeated in each row. The Relational DAS has to reverse - this process and turn the result set back into a normalised data graph, - with just one company object. - </para> - <para> - In this example the Relational DAS will examine the result set and - column specifier, find data for both the company and department - tables, find primary keys for both, and interpret each row as - containing data for a department and its parent company. If it has - not seen data for that company before (it uses the primary key to - check) it creates a company object and then a department object - underneath it. If it has seen data for that company before and - has already created the company object it just creates the - department object underneath. - </para> - - <para> - In this way the Relational DAS can retrieve and renormalise data - for multiple companies and multiple departments underneath them. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Retrieve the company and Shoe department, then delete Shoe and add IT - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das->executeQuery($dbh, -'select c.id, c.name, d.id, d.name from company c, department d where d.co_id = c.id', -array('company.id','company.name','department.id','department.name')); - -$acme = $root['company'][0]; // get the first company - will be 'Acme' -$shoe = $acme['department'][0]; // get the first department underneath - will be 'Shoe' - -unset($acme['department'][0]); - -$it = $acme->createDataObject('department'); -$it->name = 'IT'; - -$das -> applyChanges($dbh, $root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, two departments - Retrieve and Delete</title> - <para> - In this example the company and department are retrieved and - then deleted. It is not necessary to delete them individually - (although that would be possible) - deleting the company object - from the data graph also deletes any departments underneath it. - </para> - <para> - Note the way that the company object is actually deleted using the - PHP unset call. The unset has to be performed on the containing - property which in this case is - the company property on the special - root object. You must use: - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-CRUD.good-delete"> -<![CDATA[ -<?php -unset($root['company'][0]); -?> -]]> - </programlisting> - and not: - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-CRUD.bad-delete"> -<![CDATA[ -<?php -unset($acme); //WRONG -?> -]]> - </programlisting> - Simply unsetting - <varname>$acme</varname> - would destroy the variable but leave the data in the data - graph untouched. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Retrieve the company and IT department, then delete the whole company - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das->executeQuery($dbh, -'select c.id, c.name, d.id, d.name from company c, department d where d.co_id = c.id', -array('company.id','company.name','department.id','department.name')); - -$acme = $root['company'][0]; -$it = $acme['department'][0]; - -unset($root['company'][0]); - -$das -> applyChanges($dbh, $root); - -?> -]]> - </programlisting> - </example> - </para> - </section> - - <section xml:id='sdo.das.rel.examples.three-table'> - <title>Three-table example</title> - <para> - The following examples use all three tables from the company database: - the company, department, and employee tables. These introduce the final - piece of function not exercised by the examples above: the - non-containment reference - <varname>employee_of_the_month</varname>. - </para> - <para> - Like the examples above for company and department, this set of examples - is intended to illustrate the full lifecycle of such a data graph. - </para> - - - <para> - <example> - <title>One company, one department, one employee - Create</title> - <para> - In this example a company is created containing one department and - just one employee. Note that this example clears out all three tables - at the start so that the exact results of the queries can be known. - </para> - <para> - Note how once the company, department and employee have been created, - the - <varname>employee_of_the_month</varname> - property of the company can be made to point at the new employee. - As this is a non-containment reference, this cannot be done until - the employee object has been created within the graph. - Non-containment references need to be managed carefully. - For example if the employee were now deleted from under the department, - it would not be correct to try to save the graph without - first clearing or re-assigning the - <varname>employee_of_the_month</varname> - property. - The closure rule for SDO data graphs requires that any object pointed - at by a non-containment reference must also be reachable by - containment relationships. - </para> - <para> - When it comes to inserting the graph into the database, the procedure - is similar to the example of inserting the company and department, - but - <varname>employee_of_the_month</varname> - introduces an extra complexity. - The Relational DAS needs to insert the objects working down the tree - formed by containment relationships, so company, then department, then - employee. This is necessary so that it always has the auto-generated - primary key of a parent on hand to include in a child row. But when - the company row is inserted the employee who is employee of the month - has not yet been inserted and the primary key is not known. The - procedure is that after the employee record is inserted and its - primary key known, a final step is performed in which the the - company record is updated with the employee's primary key. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* -* Empty out the three tables -*************************************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$pdo_stmt = $dbh->prepare('DELETE FROM COMPANY;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM DEPARTMENT;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM EMPLOYEE;'); -$rows_affected = $pdo_stmt->execute(); - -/************************************************************************************* -* Create a tiny but complete company. -* The company name is Acme. -* There is one department, Shoe. -* There is one employee, Sue. -* The employee of the month is Sue. -*************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das -> createRootDataObject(); -$acme = $root -> createDataObject('company'); -$acme -> name = "Acme"; -$shoe = $acme -> createDataObject('department'); -$shoe -> name = 'Shoe'; -$shoe -> location = 'A-block'; -$sue = $shoe -> createDataObject('employee'); -$sue -> name = 'Sue'; -$acme -> employee_of_the_month = $sue; - -$das -> applyChanges($dbh, $root); - -echo "Wrote back Acme with one department and one employee\n"; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, one department, one employee - Retrieve and update</title> - <para> - The SQL statement passed to the Relational DAS is this time an inner - join that retrieves data from all three tables. Otherwise this example - introduces nothing that has not appeared in a previous example. - </para> - <para> - The graph is updated by the addition of a new department and employee - and some alterations to the name properties of the existing objects - in the graph. The combined changes are then written back. The - Relational DAS will process and apply an arbitrary mixture of - additions, modifications and deletions to and from the data graph. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* - * Find the company again and change various aspects. - * Change the name of the company, department and employee. - * Add a second department and a new employee. - * Change the employee of the month. - *************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das->executeQuery($dbh, - "select c.id, c.name, c.employee_of_the_month, d.id, d.name, e.id, e.name " . - "from company c, department d, employee e " . - "where e.dept_id = d.id and d.co_id = c.id and c.name='Acme'", - array('company.id','company.name','company.employee_of_the_month', - 'department.id','department.name','employee.id','employee.name')); -$acme = $root['company'][0]; - -$shoe = $acme->department[0]; -$sue = $shoe -> employee[0]; - -$it = $acme->createDataObject('department'); -$it->name = 'IT'; -$it->location = 'G-block'; -$billy = $it->createDataObject('employee'); -$billy->name = 'Billy'; - -$acme->name = 'MegaCorp'; -$shoe->name = 'Footwear'; -$sue->name = 'Susan'; - -$acme->employee_of_the_month = $billy; -$das -> applyChanges($dbh, $root); -echo "Wrote back company with extra department and employee and all the names changed (Megacorp/Footwear/Susan)\n"; - -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, two departments, two employees - Retrieve and delete</title> - <para> - The company is retrieved as a complete data graph containing five - data objects - the company, two departments and two employees. - They are all deleted by deleting the company object. Deleting an - object from the graph deletes all the object beneath it in the graph. - Five SQL DELETE statements will be generated and executed. As always - they will be qualified with a WHERE clause that contains all of the - fields that were retrieved, so that any updates to the data in the - database in the meantime by another process will be detected. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* - * Now read it one more time and delete it. - * You can delete part, apply the changes, then carry on working with the same graph but - * care is needed to keep closure - you cannot delete the employee who is eotm without - * reassigning. For safety here we delete the company all in one go. - *************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das->executeQuery($dbh, - "select c.id, c.name, c.employee_of_the_month, d.id, d.name, e.id, e.name " . - "from company c, department d, employee e " . - "where e.dept_id = d.id and d.co_id = c.id and c.name='MegaCorp';", - array('company.id','company.name','company.employee_of_the_month', - 'department.id','department.name','employee.id','employee.name')); -$megacorp = $root['company'][0]; - -unset($root['company']); -$das -> applyChanges($dbh, $root); - -echo "Deleted the company, departments and employees all in one go.\n"; - -?> -]]> - </programlisting> - </example> - </para> - - - </section> - </section> - - <section xml:id='sdo.das.rel.tracing'> - <title>Tracing</title> - <para> - You may be interested in seeing the SQL statements that are generated - in order to apply changes back to the database. At the top of the - <filename>SDO/DAS/Relational.php</filename> - you will find a number of constants which control whether the process - of constructing and executing the SQL statements is to be traced. - Try setting - <varname>DEBUG_EXECUTE_PLAN</varname> - to &true; to see the generated SQL statements. - </para> - </section> + <!-- FIXME: The rest should be reworked to follow our OOskeletons --> <!-- class definition section --> <section xml:id='sdo.das.rel.classes'> &reftitle.classes; @@ -1535,11 +106,6 @@ </section> - <!-- Include the stuff from constants.xml? --> - <!-- -&reference.sdodasrel.constants; ---> - </partintro> <!-- This seems to create the table of contents --> @@ -1566,3 +132,4 @@ vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> + http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/uodbc/constants.xml diff -u phpdoc/en/reference/uodbc/constants.xml:1.3 phpdoc/en/reference/uodbc/constants.xml:1.3.2.1 --- phpdoc/en/reference/uodbc/constants.xml:1.3 Wed Jun 20 22:25:33 2007 +++ phpdoc/en/reference/uodbc/constants.xml Fri Dec 7 14:24:26 2007 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> -<section xml:id="uodbc.constants" xmlns="http://docbook.org/ns/docbook"> +<!-- $Revision: 1.3.2.1 $ --> +<appendix xml:id="uodbc.constants" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -577,7 +577,7 @@ </listitem> </varlistentry> </variablelist> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/reference.xml?r1=1.12.2.1&r2=1.12.2.2&diff_format=u Index: phpdoc/en/reference/uodbc/reference.xml diff -u phpdoc/en/reference/uodbc/reference.xml:1.12.2.1 phpdoc/en/reference/uodbc/reference.xml:1.12.2.2 --- phpdoc/en/reference/uodbc/reference.xml:1.12.2.1 Wed Oct 3 11:41:16 2007 +++ phpdoc/en/reference/uodbc/reference.xml Fri Dec 7 14:24:26 2007 @@ -1,69 +1,8 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.12.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: bundled, external --> +<!-- $Revision: 1.12.2.2 $ --> <reference xml:id="ref.uodbc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>ODBC Functions (Unified)</title> - <titleabbrev>ODBC</titleabbrev> - - <partintro> - <section xml:id="uodbc.intro"> - &reftitle.intro; - <para> - In addition to normal ODBC support, the Unified ODBC functions in - PHP allow you to access several databases that have borrowed the - semantics of the ODBC API to implement their own API. Instead of - maintaining multiple database drivers that were all nearly - identical, these drivers have been unified into a single set of - ODBC functions. - </para> - <para> - The following databases are supported by the Unified ODBC - functions: <link xlink:href="&url.adabas;">Adabas D</link>, - <link xlink:href="&url.ibmdb2;">IBM DB2</link>, - <link xlink:href="&url.iodbc;">iODBC</link>, - <link xlink:href="&url.solid;">Solid</link>, and - <link xlink:href="&url.sybase;">Sybase SQL Anywhere</link>. - </para> - <note> - <para> - With the exception of iODBC, there is no ODBC involved when - connecting to the above databases. The functions that you - use to speak natively to them just happen to share the same - names and syntax as the ODBC functions. However, building PHP - with iODBC support enables you to use any ODBC-compliant - drivers with your PHP applications. More information on iODBC, - is available at <link xlink:href="&url.iodbc;">www.iodbc.org</link> - with the alternative unixODBC available at - <link xlink:href="&url.unixodbc;">www.unixodbc.org</link>. - </para> - </note> - </section> - - <section xml:id="uodbc.requirements"> - &reftitle.required; - <para> - To access any of the supported databases you need to have - the required libraries installed. - </para> - </section> - - &reference.uodbc.configure; - - &reference.uodbc.ini; - - <section xml:id="uodbc.resources"> - &reftitle.resources; - <para> - This extension defines two resource types: an ODBC connection identifier - and an ODBC result identifier. - </para> - </section> - - &reference.uodbc.constants; - - </partintro> &reference.uodbc.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/book.xml +++ phpdoc/en/reference/dba/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/constants.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/constants.xml +++ phpdoc/en/reference/dba/constants.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/examples.xml +++ phpdoc/en/reference/dba/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/setup.xml +++ phpdoc/en/reference/dba/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dbx/book.xml +++ phpdoc/en/reference/dbx/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dbx/setup.xml +++ phpdoc/en/reference/dbx/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/book.xml +++ phpdoc/en/reference/sdo/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/examples.xml +++ phpdoc/en/reference/sdo/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/limitations.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/limitations.xml +++ phpdoc/en/reference/sdo/limitations.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/setup.xml +++ phpdoc/en/reference/sdo/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/book.xml +++ phpdoc/en/reference/sdodasrel/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/examples.xml +++ phpdoc/en/reference/sdodasrel/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/limitations.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/limitations.xml +++ phpdoc/en/reference/sdodasrel/limitations.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/setup.xml +++ phpdoc/en/reference/sdodasrel/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/uodbc/book.xml +++ phpdoc/en/reference/uodbc/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/uodbc/setup.xml +++ phpdoc/en/reference/uodbc/setup.xml
http://cvs.php.net/viewvc.cgi/phpdoc/manual.xml.in?r1=1.224.2.27&r2=1.224.2.28&diff_format=u Index: phpdoc/manual.xml.in diff -u phpdoc/manual.xml.in:1.224.2.27 phpdoc/manual.xml.in:1.224.2.28 --- phpdoc/manual.xml.in:1.224.2.27 Thu Dec 6 23:13:19 2007 +++ phpdoc/manual.xml.in Fri Dec 7 14:24:25 2007 @@ -2,7 +2,7 @@ <!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN" "@srcdir@/docbook/docbook-xml/docbook.dtd" [ -<!-- $Revision: 1.224.2.27 $ --> <!-- Last updated to comply to manual.xml.in 1.189 --> +<!-- $Revision: 1.224.2.28 $ --> <!-- Last updated to comply to manual.xml.in 1.189 --> <!-- We use xhtml entities all over the place --> <!ENTITY % xhtml-lat1 SYSTEM "@srcdir@/entities/ISO/xhtml1-lat1.ent"> <!ENTITY % xhtml-symbol SYSTEM "@srcdir@/entities/ISO/xhtml1-symbol.ent"> @@ -186,14 +186,14 @@ <set xml:id="refs.database"> <title>Database Extensions</title> - <book xml:id="refs.database.abstract"> + <set xml:id="refs.database.abstract"> <title>Abstraction Layers</title> - &reference.dba.reference; - &reference.dbx.reference; - &reference.sdo.reference; - &reference.sdodasrel.reference; - &reference.uodbc.reference; - </book> + &reference.dba.book; + &reference.dbx.book; + &reference.sdo.book; + &reference.sdodasrel.book; + &reference.uodbc.book; + </set> <book xml:id="book.pdo"> <title>PDO</title> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/reference.xml?r1=1.26.2.1&r2=1.26.2.2&diff_format=u Index: phpdoc/en/reference/dba/reference.xml diff -u phpdoc/en/reference/dba/reference.xml:1.26.2.1 phpdoc/en/reference/dba/reference.xml:1.26.2.2 --- phpdoc/en/reference/dba/reference.xml:1.26.2.1 Wed Oct 3 11:41:09 2007 +++ phpdoc/en/reference/dba/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,261 +1,10 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.26.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: bundled --> +<!-- $Revision: 1.26.2.2 $ --> <reference xml:id="ref.dba" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Database (dbm-style) Abstraction Layer Functions</title> <titleabbrev>dba</titleabbrev> - <partintro> - <section xml:id="dba.intro"> - &reftitle.intro; - <para> - These functions build the foundation for accessing Berkeley DB - style databases. - </para> - <para> - This is a general abstraction layer for several file-based databases. - As such, functionality is limited to a common subset of features - supported by modern databases such as - <link xlink:href="&url.sleepycat;">Sleepycat Software's DB2</link>. - (This is not to be confused with IBM's DB2 software, which is - supported through the <link linkend="ref.uodbc">ODBC functions</link>.) - </para> - </section> - <section xml:id="dba.requirements"> - &reftitle.required; - <para> - The behaviour of various aspects depends on the implementation of the - underlying database. Functions such as <function>dba_optimize</function> - and <function>dba_sync</function> will do what they promise for one - database and will do nothing for others. You have to download and install - supported dba-Handlers. - <table> - <title>List of DBA handlers</title> - <tgroup cols="2"> - <thead> - <row> - <entry>Handler</entry> - <entry>Notes</entry> - </row> - </thead> - <tbody> - <row> - <entry><literal>dbm</literal></entry> - <entry> - Dbm is the oldest (original) type of Berkeley DB style - databases. You should avoid it, if possible. We do not support - the compatibility functions built into DB2 and gdbm, because - they are only compatible on the source code level, but cannot - handle the original dbm format. - </entry> - </row> - - <row> - <entry><literal>ndbm</literal></entry> - <entry> - Ndbm is a newer type and more flexible than dbm. It still has - most of the arbitrary limits of dbm (therefore it is - deprecated). - </entry> - </row> - - <row> - <entry><literal>gdbm</literal></entry> - <entry> - Gdbm is the <link xlink:href="&url.gdbm;">GNU database - manager</link>. - </entry> - </row> - - <row> - <entry><literal>db2</literal></entry> - <entry> - DB2 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB2</link>. It is described as "a programmatic toolkit that - provides high-performance built-in database support for both - standalone and client/server applications. - </entry> - </row> - - <row> - <entry><literal>db3</literal></entry> - <entry> - DB3 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB3</link>. - </entry> - </row> - - <row> - <entry><literal>db4</literal></entry> - <entry> - DB4 is <link xlink:href="&url.sleepycat;">Sleepycat Software's - DB4</link>. This is available since PHP 4.3.2. - </entry> - </row> - - <row> - <entry><literal>cdb</literal></entry> - <entry> - Cdb is "a fast, reliable, lightweight package for creating and - reading constant databases." It is from the author of qmail and - can be found at <link xlink:href="&url.cdb;">&url.cdb;</link>. Since it is - constant, we support only reading operations. And since PHP 4.3.0 - we support writing (not updating) through the internal cdb library. - </entry> - </row> - - <row> - <entry><literal>cdb_make</literal></entry> - <entry> - Since PHP 4.3.0 we support creation (not updating) of cdb files - when the bundled cdb library is used. - </entry> - </row> - - <row> - <entry><literal>flatfile</literal></entry> - <entry> - This is available since PHP 4.3.0 for compatibility with the deprecated - <link linkend="ref.dbm">dbm</link> extension only and should be avoided. - However you may use this where files were created in this format. That - happens when configure could not find any external library. - </entry> - </row> - - <row> - <entry><literal>inifile</literal></entry> - <entry> - This is available since PHP 4.3.3 to be able to modify php.ini files - from within PHP scripts. When working with ini files you can pass arrays - of the form array(0=>group,1=>value_name) or strings of the form - "[group]value_name" where group is optional. As the functions - <function>dba_firstkey</function> and <function>dba_nextkey</function> - return string representations of the key there is a new function - <function>dba_key_split</function> available since PHP 5 which allows - to convert the string keys into array keys without loosing &false;. - </entry> - </row> - - <row> - <entry><literal>qdbm</literal></entry> - <entry> - This is available since PHP 5.0.0. The qdbm library can be loaded from - <link xlink:href="http://qdbm.sourceforge.net">http://qdbm.sourceforge.net</link>. - </entry> - </row> - - </tbody> - </tgroup> - </table> - </para> - <para> - When invoking the <function>dba_open</function> or - <function>dba_popen</function> functions, one of the - handler names must be supplied as an argument. The actually - available list of handlers is displayed by invoking - <function>phpinfo</function> or <function>dba_handlers</function>. - </para> - </section> - - &reference.dba.configure; - - <section xml:id="dba.runtime"> - &reftitle.runtime; - &no.config; - </section> - - <section xml:id="dba.resources"> - &reftitle.resources; - <para> - The functions <function>dba_open</function> and - <function>dba_popen</function> return a handle to the specified - database file to access which is used by all other dba-function calls. - </para> - </section> - - <section xml:id="dba.constants"> - &reftitle.constants; - &no.constants; - </section> - - <section xml:id="dba.examples"> - &reftitle.examples; - <para> - <example> - <title>DBA example</title> - <programlisting role="php"> -<![CDATA[ -<?php - -$id = dba_open("/tmp/test.db", "n", "db2"); - -if (!$id) { - echo "dba_open failed\n"; - exit; -} - -dba_replace("key", "This is an example!", $id); - -if (dba_exists("key", $id)) { - echo dba_fetch("key", $id); - dba_delete("key", $id); -} - -dba_close($id); -?> -]]> - </programlisting> - </example> - </para> - <para> - DBA is binary safe and does not have any arbitrary limits. - However, it inherits all limits set by the underlying - database implementation. - </para> - <para> - All file-based databases must provide a way of setting the file - mode of a new created database, if that is possible at all. The - file mode is commonly passed as the fourth argument to - <function>dba_open</function> or <function>dba_popen</function>. - </para> - <para> - You can access all entries of a database in a linear way by using the - <function>dba_firstkey</function> and <function>dba_nextkey</function> - functions. You may not change the database while traversing it. - </para> - <para> - <example> - <title>Traversing a database</title> - <programlisting role="php"> -<![CDATA[ -<?php - -// ...open database... - -$key = dba_firstkey($id); - -while ($key != false) { - if (true) { // remember the key to perform some action later - $handle_later[] = $key; - } - $key = dba_nextkey($id); -} - -foreach ($handle_later as $val) { - dba_delete($val, $id); -} - -?> -]]> - </programlisting> - </example> - </para> - </section> - - </partintro> - &reference.dba.functions.entities; </reference> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/constants.xml?r1=1.11&r2=1.11.2.1&diff_format=u Index: phpdoc/en/reference/dbx/constants.xml diff -u phpdoc/en/reference/dbx/constants.xml:1.11 phpdoc/en/reference/dbx/constants.xml:1.11.2.1 --- phpdoc/en/reference/dbx/constants.xml:1.11 Wed Jun 20 22:24:21 2007 +++ phpdoc/en/reference/dbx/constants.xml Fri Dec 7 14:24:25 2007 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.11 $ --> - <section xml:id="constants.dbx" xmlns="http://docbook.org/ns/docbook"> +<!-- $Revision: 1.11.2.1 $ --> + <appendix xml:id="constants.dbx" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -236,7 +236,7 @@ </listitem> </varlistentry> </variablelist> - </section> + </appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/reference.xml?r1=1.20.2.1&r2=1.20.2.2&diff_format=u Index: phpdoc/en/reference/dbx/reference.xml diff -u phpdoc/en/reference/dbx/reference.xml:1.20.2.1 phpdoc/en/reference/dbx/reference.xml:1.20.2.2 --- phpdoc/en/reference/dbx/reference.xml:1.20.2.1 Wed Oct 3 11:41:09 2007 +++ phpdoc/en/reference/dbx/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,102 +1,8 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.20.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: pecl, external --> +<!-- $Revision: 1.20.2.2 $ --> <reference xml:id="ref.dbx" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> - <title>dbx Functions</title> - <titleabbrev>dbx</titleabbrev> - - <partintro> - <section xml:id="dbx.intro"> - &reftitle.intro; - <para> - The dbx module is a database abstraction layer (db 'X', where 'X' - is a supported database). The dbx functions allow you to access - all supported databases using a single calling convention. - The dbx-functions themselves do not interface directly to the - databases, but interface to the modules that are used to support - these databases. - </para> - <note> - <para> - &pecl.moved-ver;5.1.0. - </para> - </note> - </section> - - <section xml:id="dbx.required"> - &reftitle.required; - <para> - To be able to use a database with the dbx-module, the module must be either - linked or loaded into PHP, and the database module must be supported by the - dbx-module. Currently, the following databases are supported, but others - will follow: - <itemizedlist> - <listitem> - <simpara> - <link linkend="ref.fbsql">FrontBase</link> (available from PHP 4.1.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.mssql">Microsoft SQL Server</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.mysql">MySQL</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.uodbc">ODBC</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.pgsql">PostgreSQL</link> - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.sybase">Sybase-CT</link> (available from PHP 4.2.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.oci8">Oracle (oci8)</link> (available from PHP 4.3.0). - </simpara> - </listitem> - <listitem> - <simpara> - <link linkend="ref.sqlite">SQLite</link> (PHP 5). - </simpara> - </listitem> - </itemizedlist> - </para> - <para> - Documentation for adding additional database support to dbx can be - found at <link xlink:href="&url.dbx.docs;">&url.dbx.docs;</link>. - </para> - </section> - - &reference.dbx.configure; - - &reference.dbx.ini; - - <section xml:id="dbx.resources"> - &reftitle.resources; - <para> - There are two resource types used in the dbx module. The first one is the - link-<type>object</type> for a database connection, the second a - result-<type>object</type> which holds the result of a query. - </para> - </section> - - &reference.dbx.constants; - - </partintro> + <title>dbx &Functions;</title> &reference.dbx.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/sdo/constants.xml diff -u phpdoc/en/reference/sdo/constants.xml:1.3 phpdoc/en/reference/sdo/constants.xml:1.3.2.1 --- phpdoc/en/reference/sdo/constants.xml:1.3 Wed Jun 20 22:25:19 2007 +++ phpdoc/en/reference/sdo/constants.xml Fri Dec 7 14:24:25 2007 @@ -1,7 +1,7 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.3.2.1 $ --> <!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> -<section xml:id="sdo.constants" xmlns="http://docbook.org/ns/docbook"> +<appendix xml:id="sdo.constants" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -50,7 +50,7 @@ </listitem> </varlistentry> </variablelist> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/reference.xml?r1=1.28.2.1&r2=1.28.2.2&diff_format=u Index: phpdoc/en/reference/sdo/reference.xml diff -u phpdoc/en/reference/sdo/reference.xml:1.28.2.1 phpdoc/en/reference/sdo/reference.xml:1.28.2.2 --- phpdoc/en/reference/sdo/reference.xml:1.28.2.1 Wed Oct 3 11:41:14 2007 +++ phpdoc/en/reference/sdo/reference.xml Fri Dec 7 14:24:25 2007 @@ -1,247 +1,10 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.28.2.1 $ --> -<!-- Purpose: xml --> -<!-- Membership: pecl --> +<!-- $Revision: 1.28.2.2 $ --> <reference xml:id="ref.sdo" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> - <title>SDO Functions</title> - <titleabbrev>SDO</titleabbrev> + <title>SDO &Functions;</title> <partintro> - <section xml:id="sdo.intro"> - &reftitle.intro; - <para> - Service Data Objects (SDOs) enable PHP applications to work with - data from different sources (like a database query, an XML file, - and a spreadsheet) using a single interface. - </para> - <para> - Each different kind of data source requires a Data Access Service - (DAS) to provide access to the data in the data source. - In your PHP application, you use a DAS to create an SDO - instance that represents some data in the data source. You can then - set and get values in the SDO instance using the standard SDO - interface. Finally, you use a DAS to write the modified data back - to a data source, typically the same one. - </para> - <para> - See the - <link linkend="sdo.das.table">list of Data Access Services</link> - for details on those - currently available. In addition to the provided DASs, SDO also - provides interfaces to enable others to be implemented - (see the section on <link linkend="sdo.class.sdo-das-spis">SDO Data - Access Services Interface</link> for more details). - </para> - <para> - This extension is derived from concepts taken from the - <link xlink:href="&url.ibm.sdo;">Service Data Objects specification</link>. - It includes a version of the - <link xlink:href="&url.apache.tuscany;">Apache Tuscany</link> SDO for C++ project. - </para> - - <section xml:id="sdo.intro.structure"> - <title>The Structure of a Service Data Object</title> - <para> - A Service Data Object instance is made up of a tree of data objects. - The tree is defined by containment relationships between the data - objects. For example, a Company data object might consist of a number - of Department data objects and therefore the Company would have - a containment relationship to the Departments. - </para> - <para> An SDO may also have non-containment references between data objects in the - tree. For example, one Employee data object might reference another Employee to - identify a career mentor. - </para> - <para> - As well as data objects referencing each other, they can also have - primitive properties. For example, the Company data object might - have a property called "name" of type string, for holding the name - of the company (for example, "Acme"). - </para> - <para> Each of these properties of a data object - containment relationships, - non-containment references, or primitive properties - may be many-valued or - single-valued. In the above examples, Departments is many-valued and - the Company name is single-valued. - </para> - <para> In PHP, each SDO data object is represented as a PHP object. The properties of the - data object can be accessed using either object syntax or associative array syntax. - We'll see some examples of this later. - </para> - </section> - </section> - - <section xml:id="sdo.requirements"> - &reftitle.required; - <para> - The SDO extension requires PHP 5.1.0 or higher. It also requires the - libxml2 library. Normally libxml2 will already be installed, but if - not, it can be downloaded from - <link xlink:href='&url.libxml;'> - &url.libxml; - </link> - . - </para> - </section> - - <section xml:id="sdo.installation"> - &reftitle.install; - <note> - <para> - Earlier versions of the SDO extension required a separate shared - library for the XML DAS. This is now obsolete and any references to - <filename>php_sdo_das_xml.dll</filename> - or - <filename>sdo_das_xml.so</filename> - should be removed from your - &php.ini; - . - </para> - </note> - <procedure xml:id='sdo.install.unix'> - <title>Unix systems</title> - <step> - <para> - The three SDO components - the SDO core, the XML DAS and the - Relational DAS - are packaged together with Service Component - Architecture (SCA) into one PECL project, SCA_SDO, so you can - download SCA and all three parts of SDO with the command: - <screen> - <![CDATA[ -pecl install SCA_SDO -]]> - </screen> - </para> - <para> - This command will build the SDO shared library as well as - installing the PHP files that make up SCA and the SDO - Relational DAS. - </para> - <para> - If you want to use the latest beta version, then instead run: - <screen> - <![CDATA[ -pecl install SCA_SDO-beta -]]> - </screen> - </para> - </step> - <step> - <para> - The - <command>pecl</command> - command automatically installs the SDO module into your PHP - extensions directory. To enable the SDO extension you must add the - following line to - &php.ini; - : - <screen> - <![CDATA[ -extension=sdo.so -]]> - </screen> - </para> - <para> - For more information about building PECL packages, consult the - <link linkend="install.pecl">PECL installation</link> - section of the manual. - </para> - </step> - </procedure> - - <procedure xml:id='sdo.install.win32'> - <title>Windows</title> - <step> - <para> - The latest SDO DLL can be downloaded from - <link xlink:href='&url.pecl.win.ext;php_sdo.dll'>php_sdo.dll</link> - . - </para> - <para> - Note that currently the - <link xlink:href='&url.pecl.win;'>pecl4win</link> - site does not provide this binary at the current release level; - you can only download the latest level. - </para> - </step> - <step> - <para> - The - <command>pecl</command> - command automatically installs the SDO module into your PHP - extensions directory. To enable the SDO extension you must add the - following line to - &php.ini; - : - <screen> - <![CDATA[ -extension=php_sdo.dll -]]> - </screen> - </para> - </step> - <step> - <para> - The Relational DAS can be downloaded and installed with the - command: - <screen> - <![CDATA[ -pecl install -B sdo -]]> - </screen> - </para> - <para> - The Relational DAS is written in PHP. You may need to update your - <link linkend="ini.include-path">include_path</link> - in - &php.ini; - to point to the directory that contains - <filename>sdo/DAS/Relational</filename> - . - </para> - </step> - </procedure> - - <procedure xml:id='sdo.build.linux.steps'> - <title>Building SDO on Linux</title> - <para> - This section describes how to build the SDO core and XML DAS on - Linux. You would only need to know how to do this if you wish to - build a recent version that you have checked out of CVS. - </para> - <step> - <para> - Change to the main extension directory: - <command>cd < wherever your sdo code is ></command> - </para> - </step> - <step> - <para> - Run - <command>phpize</command> - , which will set up the environment to compile SDO. - </para> - </step> - <step> - <para> - Next, run - <command>./configure; make; make install</command> - . Please note, you may need to login as root to install the - extension. - </para> - </step> - <step> - <para> - Make sure that the module is loaded by PHP, by adding - <filename>extension=sdo.so</filename> - to your - &php.ini; - file. - </para> - </step> - </procedure> - </section> - <section xml:id="sdo.das.table"> <title>Data Access Services</title> <para> @@ -280,843 +43,7 @@ </para> </section> - <section xml:id='sdo.limitations'> - <title>Limitations</title> - <procedure xml:id='sdo.limitations.implementation'> - <title>Implementation Limitations</title> - <para> - The following are limitations in the current SDO implementation: - </para> - <step> - <para> - There is no support for multi-byte character sets. - This will be considered, depending on community requirements, - in the Unicode-enabled version of PHP. - See <link linkend="ref.unicode">Unicode Functions</link>. - </para> - </step> - </procedure> - <procedure xml:id='sdo.limitations.sdo'> - <title>SDO Limitations</title> - <para> - The following SDO 2.0 concepts are not supported in the current - PHP implementation. - It is not necessarily the case that these will all be added over time. - Their inclusion will depend on community requirements. - </para> - <step> - <para> - Bi-directional relationships. - </para> - </step> - <step> - <para> - Type and property alias names. - </para> - </step> - <step> - <para> - Read-only properties. - </para> - </step> - <step> - <para> - The Helper classes defined in SDO 2.0 are not directly implemented. - However equivalent function is provided in a more natural way for PHP. - For example the function of <command>CopyHelper::copy()</command> - is provided by applying the PHP - <link linkend='language.oop5.cloning'>clone</link> keyword to a data object. - </para> - </step> - </procedure> - </section> - - <section xml:id='sdo.examples'> - &reftitle.examples; - <para> - The examples below assume an SDO created with the schema - and instance information shown below, using the XML Data Access Service. - </para> - <para> - The instance document below describes a single company, - called 'MegaCorp', which contains a single department, - called 'Advanced Technologies'. - The Advanced Technologies department contains three employees. - The company employeeOfTheMonth is referencing the second employee, - 'Jane Doe'. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<?xml version="1.0" encoding="UTF-8" ?> -<company xmlns="companyNS" name="MegaCorp" - employeeOfTheMonth="E0003"> - <departments name="Advanced Technologies" location="NY" number="123"> - <employees name="John Jones" SN="E0001"/> - <employees name="Jane Doe" SN="E0003"/> - <employees name="Al Smith" SN="E0004" manager="true"/> - </departments> -</company> -]]> - </programlisting> - </para> - <para> The root element of the schema is a company. The company contains departments, and - each department contains employees. Each element has a number of attributes to store - things like name, serial number, and so on. Finally, the company also has an IDREF - attribute which identifies one of the employees as the 'employeeOfTheMonth'. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<xsd:schema - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:sdo="commonj.sdo" - xmlns:sdoxml="commonj.sdo/xml" - xmlns:company="companyNS" - targetNamespace="companyNS"> - <xsd:element name="company" type="company:CompanyType"/> - <xsd:complexType name="CompanyType"> - <xsd:sequence> - <xsd:element name="departments" type="company:DepartmentType" - maxOccurs="unbounded"/> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="employeeOfTheMonth" type="xsd:IDREF" - sdoxml:propertyType="company:EmployeeType"/> - </xsd:complexType> - <xsd:complexType name="DepartmentType"> - <xsd:sequence> - <xsd:element name="employees" type="company:EmployeeType" - maxOccurs="unbounded"/> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="location" type="xsd:string"/> - <xsd:attribute name="number" type="xsd:int"/> - </xsd:complexType> - <xsd:complexType name="EmployeeType"> - <xsd:attribute name="name" type="xsd:string"/> - <xsd:attribute name="SN" type="xsd:ID"/> - <xsd:attribute name="manager" type="xsd:boolean"/> - </xsd:complexType> -</xsd:schema> -]]> - </programlisting> - </para> - <para>The XML Data Access Service maps the schema to an SDO. Attributes such as "name" - become primitive properties, the sequence of employees becomes a many-valued - containment relationship, and so on. Note that the containment relationships are - expressed as one complex type within another, whereas non-containment references are - expressed in terms of ID and IDREF, with a special - <command>sdoxml:propertyType</command> attribute specifying the type of the - non-containment reference. - </para> - </section> - - <section xml:id="sdo.sample.getset"> - <title>Setting and Getting Property Values</title> - <para> The following examples assume - <command>$company</command> is the root of a tree of data objects created from the - schema and instance document shown above. - </para> - <para> - <example> - <title>Access via property name</title> - <para> - Data object properties can be accessed using the object property - access syntax. The following sets the company name to 'Acme'. - </para> - <programlisting role="php" xml:id="sdo.examples.propname"> -<![CDATA[ -<?php - $company->name = 'Acme'; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Access via property name as array index</title> - <para>We can also access properties using associative array syntax. The simplest - form of this uses the property name as the array index. For example, the following sets - the company name and gets the employeeOfTheMonth. - </para> - <programlisting role="php" xml:id="sdo.examples.simplexpath"> -<![CDATA[ -<?php - $company['name'] = 'UltraCorp'; - $eotm = $company['employeeOfTheMonth']; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Data Object iteration</title> - <para> - We can iterate over the properties of a data object using foreach. - The following iterates over the properties of the employee of the month. - </para> - <programlisting role="php" xml:id="sdo.examples.doiter"> -<![CDATA[ -<?php - $eotm = $company->employeeOfTheMonth; - foreach ($eotm as $name => $value) { - echo "$name: $value\n"; - } -?> -]]> - </programlisting> - <para> - which will output: - </para> - <programlisting xml:id="sdo.examples.doiter-output"> -<![CDATA[ -name: Jane Doe -SN: E0003 -]]> - </programlisting> - <para> - The 'manager' property is not output, because it has not been set. - </para> - </example> - </para> - - <para> - <example> - <title>Access many-valued property by name</title> - <para> Many-valued data object properties can also be accessed using the object - property name syntax. The following gets the list of departments. - </para> - <programlisting role="php" xml:id="sdo.examples.mvpname"> -<![CDATA[ -<?php - $departments = $company->departments; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Many-valued element access</title> - <para> - We can access individual elements of many-valued properties using array - syntax. The following accesses the first department in the company. - </para> - <programlisting role="php" xml:id="sdo.examples.mvaccess"> -<![CDATA[ -<?php - $ad_tech_dept = $company->departments[0]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Many-valued property iteration</title> - <para> - Many-valued properties can also be iterated over using - foreach. The following iterates over the company's departments. - </para> - <programlisting role="php" xml:id="sdo.examples.mvpiter"> -<![CDATA[ -<?php - foreach ($company->departments as $department) { - // ... - } -?> -]]> - </programlisting> - <para> - Each iteration will assign the next department in the - list to the variable <command>$department</command>. - </para> - </example> - </para> - - <para> - <example> - <title>Chained property access</title> - <para> We can chain property references on a single line. - The following sets and gets the name of the first department. - </para> - <programlisting role="php" xml:id="sdo.examples.nestedprop"> -<![CDATA[ -<?php - $company->departments[0]->name = 'Emerging Technologies'; - $dept_name = $company->departments[0]->name; -?> -]]> - </programlisting> - <para>Using the associative array syntax, this is equivalent to</para> - <programlisting role="php" xml:id="sdo.examples.chainarray"> -<![CDATA[ -<?php - $company['departments'][0]['name'] = 'Emerging Technologies'; - $dept_name = $company['departments'][0]['name']; -?> -]]> - </programlisting> - <para> In either case, the dept_name variable is set to 'Emerging Technologies'. - </para> - </example> - </para> - - <para> - <example> - <title>XPath navigation</title> - <para> The associative array index can be an XPath-like expression. Valid - expressions are defined by an augmented sub-set of XPath. - </para> - <para> - Two forms of indexing into many-valued properties are supported. - The first is the standard XPath array syntax with the indexing - starting at one, the second is an SDO extension to XPath with an index - starting at zero. The standard syntax is: - </para> - <programlisting role="php" xml:id="sdo.examples.xpath1nav"> -<![CDATA[ -<?php - $jane_doe = $company["departments[1]/employees[2]"]; -?> -]]> - </programlisting> - <para>and the SDO XPath extension syntax is:</para> - <programlisting role="php" xml:id="sdo.examples.xpath0nav"> -<![CDATA[ -<?php - $jane_doe = $company["departments.0/employees.1"]; -?> -]]> - </programlisting> - <para> - Both these examples get the second employee from the first department. - </para> - </example> - </para> - - <para> - <example> - <title>XPath querying</title> - <para> - We can use XPath to query and identify parts of a data object based - on instance data. The following retrieves the manager from the - 'Advanced Technologies' department. - </para> - <programlisting role="php" xml:id="sdo.examples.xpathquery"> - <![CDATA[ -<?php - $ad_tech_mgr = - $company["departments[name='Advanced Technologies']/employees[manager=true]"]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Creating child data objects</title> - <para> - A data object can be a factory for its child data objects. - A child data object is automatically part of the data graph. - The following add a new employee to the 'Advanced Technologies' - department. - </para> - <programlisting role="php" xml:id="sdo.examples.create"> -<![CDATA[ -<?php - $ad_tech_dept = $company["departments[name='Advanced Technologies']"]; - $new_hire = $ad_tech_dept->createDataObject('employees'); - $new_hire->name = 'John Johnson'; - $new_hire->SN = 'E0005'; - $new_hire->manager = false; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a primitive property</title> - <para> - We can use the <function>isset</function> and - <function>unset</function> functions to test and remove items - from the data object. - </para> - <para> - The following clears the name of the first department. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetprim"> -<![CDATA[ -<?php - unset($company->departments[0]->name); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a data object</title> - <para> - unset can also be used to remove a data object from the tree. - The following example shows John Jones leaving the company. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetdo"> -<![CDATA[ -<?php - unset($company->departments[0]->employees[0]); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Unset a referenced data object</title> - <para> - The following removes the 'employeeOfTheMonth' from the company. - If this were a containment relationship then the - employee would be removed from the company - (probably not a good idea to sack your best employee each month!), - but since this is a non-containment reference, - the employee being referenced will remain in the - department in the company, - but will no longer be accessible via the employeeOfTheMonth property. - </para> - <programlisting role="php" xml:id="sdo.examples.unsetrefdo"> -<![CDATA[ -<?php - if (isset($company->employeeOfTheMonth)) { - unset($company->employeeOfTheMonth); - } -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Access via property index</title> - <para> Data object properties can be accessed via their property index using array - syntax. The property index is the position at which the property's definition - appears in the model (in this case the xml schema). We can see from the schema listing - above that the company name attribute is the second company property (the SDO - interface makes no distinction between XML attributes and elements). The following - sets the company name to 'Acme', with the same result as - <link linkend="sdo.examples.propname">Access via property name</link> - </para> - <programlisting role="php" xml:id="sdo.examples.propindex"> -<![CDATA[ -<?php - $company[1] = 'Acme'; -?> -]]> - </programlisting> - <para> Using the index directly in this way is likely to be fragile. Normally the - property name syntax should be preferred, but the property index may be required - in special cases. - </para> - </example> - </para> - - </section> - - <section xml:id="sdo.sample.sequence"> - <title>Working with Sequenced Data Objects</title> - <para> - Sequenced data objects are SDOs which can track property - ordering across the properties of a data object. They can also - contain unstructured text elements (text element which do not - belong to any of the SDO's properties). Sequenced data objects are - useful for working with XML documents which allow unstructured text (i.e. - mixed=true) or if the elements can be interleaved ( - <![CDATA[<A/><B/><A/>]]>). This can occur for example when - the schema defines maxOccurs>1 on a - element which is a complexType with a choice order indicator. - </para> - <para> - The examples below assume an SDO created with the following schema - and instance information, using the XML Data Access Service. - </para> - <para> - The schema below describes the format of a letter. The letter can - optionally contain three properties; date, firstName, and lastName. - The schema states <command>mixed="true"</command> which means that - unstructured text can be interspersed between the three properties. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:letter="http://letterSchema" - targetNamespace="http://letterSchema"> - <xsd:element name="letters" type="letter:FormLetter"/> - <xsd:complexType name="FormLetter" mixed="true"> - <xsd:sequence> - <xsd:element name="date" minOccurs="0" type="xsd:string"/> - <xsd:element name="firstName" minOccurs="0" type="xsd:string"/> - <xsd:element name="lastName" minOccurs="0" type="xsd:string"/> - </xsd:sequence> - </xsd:complexType> -</xsd:schema> - ]]> - </programlisting> - </para> - - <para> - The following is an instance letter document. It contains the - three letter properties; date, firstName and lastName, and has - unstructured text elements for the address and letter body. - </para> - <para> - <programlisting role="xml"> -<![CDATA[ -<letter:letters xmlns:letter="http://letterSchema"> - <date>March 1, 2005</date> - Mutual of Omaha - Wild Kingdom, USA - Dear - <firstName>Casy</firstName> - <lastName>Crocodile</lastName> - Please buy more shark repellent. - Your premium is past due. -</letter:letters> - ]]> - </programlisting> - </para> - <para> - When loaded, the letter data object will have the sequence and - property indices shown in the table below: - <informaltable> - <tgroup cols='3'> - <thead> - <row> - <entry>Sequence Index</entry> - <entry>Property Index:Name</entry> - <entry>Value</entry> - </row> - </thead> - <tbody> - <row> - <entry>0</entry> - <entry>0:date</entry> - <entry>March 1, 2005</entry> - </row> - <row> - <entry>1</entry> - <entry>-</entry> - <entry>Mutual of Omaha</entry> - </row> - <row> - <entry>2</entry> - <entry>-</entry> - <entry>Wild Kingdom, USA</entry> - </row> - <row> - <entry>3</entry> - <entry>-</entry> - <entry>Dear</entry> - </row> - <row> - <entry>4</entry> - <entry>1:firstName</entry> - <entry>Casy</entry> - </row> - <row> - <entry>5</entry> - <entry>2:lastName</entry> - <entry>Crocodile</entry> - </row> - <row> - <entry>6</entry> - <entry>-</entry> - <entry>Please buy more shark repellent.</entry> - </row> - <row> - <entry>7</entry> - <entry>-</entry> - <entry>Your premium is past due.</entry> - </row> - </tbody> - </tgroup> - </informaltable> - </para> - - <para> - To ensure sequence indices are maintained, sequenced data objects - should be manipulated through the SDO_Sequence interface. - This allows the data object's instance data to be manipulated - in terms of the sequence index as opposed to the property index - (shown in the table above). - The following examples assume the letter instance has been - loaded into a data object referenced by the variable - <command>$letter</command>. - <example> - <title>Getting the SDO_Sequence interface</title> - <para> - We obtain a data object's sequence using the - <function>getSequence</function> - method. The follow gets the - sequence for the letter data object. - </para> - <programlisting role="php" xml:id="sdo.examples.seqinterface"> -<![CDATA[ -<?php - $letter_seq = $letter->getSequence(); -?> -]]> - </programlisting> - </example> - </para> - <para> - All subsequent examples assume that the - <command>$letter_seq</command> - variable has been assigned the sequence for the letter data object. - </para> - - <para> - <example> - <title>Get/set sequence values</title> - <para> - We can get and set individual values (including unstructured text) - using the sequence index. - The following sets the firstName to 'Snappy' and gets the last - sequence values (the unstructured text, 'Your premium is past due.'). - </para> - <programlisting role="php" xml:id="sdo.examples.getsetseq"> -<![CDATA[ -<?php - $letter_seq[4] = 'Snappy'; - $text = $letter_seq[count($letter_seq) - 1]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Sequence iteration</title> - <para> - We can iterate through the individual sequence values using foreach. - The following runs through the individual values in sequence order. - </para> - <programlisting role="php" xml:id="sdo.examples.seqiter"> -<![CDATA[ -<?php - foreach ($letter->getSequence() as $value) { - // ... - } -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Sequence versus Data Object</title> - <para> - Setting values through the data object interface may result in the - value not being part of the sequence. A value set through the data - object will only be accessible through the sequence if the property was - already part of the sequence. The following example sets the - lastName through the data object and gets it through the sequence. - This is fine because lastName already exists in the sequence. If - it had not previously been set, then lastName would be set to - 'Smith', but would not be part of the sequence. - </para> - <programlisting role="php" xml:id="sdo.examples.seqvsdo"> -<![CDATA[ -<?php - $letter[2] = 'Smith'; - $last_name = $letter_seq[5]; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Adding to a sequence</title> - <para> - We can add new values to a sequence using the - <link linkend='function.SDO-Sequence-insert'><function>SDO_Sequence::insert</function></link> - method. The following examples assume that the 'firstName' and - 'lastName' properties are initially unset. - </para> - <programlisting role="php" xml:id="sdo.examples.seqadd"> -<![CDATA[ -<?php - // Append a firstName value to the sequence - // value: 'Smith' - // sequence index: NULL (append) - // propertyIdentifier: 1 (firtName property index) - $letter_seq->insert('Smith', NULL, 1); - - // Append a lastName value to the sequence - // value: 'Jones' - // sequence index: NULL (append) - // propertyIdentifier: 'lastName' (lastName property name) - $letter_seq->insert('Jones', NULL, 'lastName'); - - // Append unstructured text - // value: 'Cancel Subscription.' - // sequence index: absent (append) - // propertyIdentifier: absent (unstructured text) - $letter_seq->insert('Cancel Subscription.'); - - // Insert new unstructured text. Subsequent sequence values - // are shifted up. - // value: 'Care of:' - // sequence index: 1 (insert as second element) - // propertyIdentifier: absent (unstructured text) - $letter_seq->insert('Care of:', 1); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Removing from a sequence</title> - <para> - We can use the <function>isset</function> and - <function>unset</function> functions to test and remove items - from the sequence (Note: <function>unset</function> currently - leaves the values in the data object, but this behaviour is - likely to change to also remove the data from the data object). - A sequence behaves like a contiguous list; therefore, removing - items from the middle will shift entries at higher indices - down. The following example tests to see if the first sequence - element is set and unsets it if is. - </para> - <programlisting role="php" xml:id="sdo.examples.seqremove"> -<![CDATA[ -<?php - if (isset($letter_seq[0])) { - unset($letter_seq[0]); - } -?> -]]> - </programlisting> - </example> - </para> - - </section> - - - <section xml:id="sdo.sample.reflection"> - <title>Reflecting on Service Data Objects</title> - <para> - SDOs have a knowledge of the structure they have been created to - represent (the model). For example, a Company SDO created using - <link linkend="sdo.examples">the Company XML schema</link> above - would only be permitted to contain DepartmentType data objects - which in turn could only contain EmployeeType data objects. - </para> - <para> - Sometimes it is useful to be able to access this model information at - runtime. For example, this could be used to automatically generate - a user interface for populating a data object. The model information - is accessed using reflection. - </para> - - <para> - <example> - <title>Reflecting on a Data Object</title> - <para> - The following example shows how we can reflect on an empty Employee - data object. - </para> - <programlisting role="php" xml:id="sdo.examples.reflection"> -<![CDATA[ -<?php - // Create the employee data object (e.g. from an XML Data Access Service) - $employee = ...; - $reflection = new SDO_Model_ReflectionDataObject($employee); - print($reflection); -?> -]]> - </programlisting> - &example.outputs; - - <screen> -<![CDATA[ -object(SDO_Model_ReflectionDataObject)#4 { - ROOT OBJECT - Type { -companyNS:EmployeeType[3] { commonj.sdo:String $name; -commonj.sdo:String $SN; commonj.sdo:Boolean $manager; } } -]]> - </screen> - <para> - Using print on the SDO_Model_ReflectionDataObject writes out the data - object's model. We can see from the output how the type - companyNS:EmployeeType has three properties and we can see the names - of the properties along with their types. Note, the primitive types - are listed as SDO types (e.g. commonj.sdo namespace, String type). - It is worth noting that this is the SDO model and when these are - surfaced to an application they can be treated as the PHP equivalent - types (e.g. string and boolean). - </para> - </example> - </para> - - <para> - <example> - <title>Accessing the type information</title> - <para> - We can query the type information of a data object using reflection. - The following example checks the type corresponds to a data object - rather than a primitive and then iterates through the properties of - the type, writing out the name of each property ($type and $property - are SDO_Model_Type and SDO_Model_Property objects, respectively). - </para> - <programlisting role="php" xml:id="sdo.examples.reflection.type"> -<![CDATA[ -<?php - // Create the employee data object (e.g. from an XML Data Access Service) - $employee = ...; - $reflection = new SDO_Model_ReflectionDataObject($employee); - $type = $reflection->getType(); - if (! $type->isDataType()) { - foreach ($type->getProperties() as $property) { - print $property->getName() . "\n"; - } - } -?> -]]> - </programlisting> - &example.outputs; - <screen> -<![CDATA[ -name -SN -manager -]]> - </screen> - </example> - </para> - - </section> - - - - + <!-- FIXME: Everything below should be removed and follow our OO skeletons --> <!-- class definition section --> <section xml:id='sdo.classes'> @@ -1718,8 +645,6 @@ </section> </section> - &reference.sdo.constants; - </partintro> &reference.sdo.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/sdodasrel/constants.xml diff -u phpdoc/en/reference/sdodasrel/constants.xml:1.3 phpdoc/en/reference/sdodasrel/constants.xml:1.3.2.1 --- phpdoc/en/reference/sdodasrel/constants.xml:1.3 Wed Jun 20 22:25:19 2007 +++ phpdoc/en/reference/sdodasrel/constants.xml Fri Dec 7 14:24:26 2007 @@ -1,14 +1,13 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.3 $ --> -<!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> -<section xml:id="sdodasrel.constants" xmlns="http://docbook.org/ns/docbook"> - <!-- &reftitle.constants; - &extension.constants; - --> +<!-- $Revision: 1.3.2.1 $ --> + +<appendix xml:id="sdodasrel.constants" xmlns="http://docbook.org/ns/docbook"> + &reftitle.constants; + &extension.constants; <para> The Relational DAS introduces no predefined constants. </para> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/reference.xml?r1=1.21.2.2&r2=1.21.2.3&diff_format=u Index: phpdoc/en/reference/sdodasrel/reference.xml diff -u phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.2 phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.3 --- phpdoc/en/reference/sdodasrel/reference.xml:1.21.2.2 Fri Nov 2 12:13:28 2007 +++ phpdoc/en/reference/sdodasrel/reference.xml Fri Dec 7 14:24:26 2007 @@ -1,1442 +1,13 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.21.2.2 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: pecl --> -<!-- State: experimental --> +<!-- $Revision: 1.21.2.3 $ --> <reference xml:id="ref.sdo.das.rel" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>SDO Relational Data Access Service Functions</title> <titleabbrev>SDO-DAS-Relational</titleabbrev> <partintro> - <section xml:id="sdo.das.rel.intro"> - &reftitle.intro; - <para> - <!-- This warns that the extension is experimental --> - &warn.experimental; - </para> - <para> - In order to use the Relational Data Access Service for - Service Data Objects, - you will need to understand some of the concepts behind SDO: - the data graph, the data object, the disconnected way of working, - the change summary, XPath and property expressions, and so on. - If you are not familiar with these ideas, you might want to look first at - <link linkend='ref.sdo'>the section on SDO</link>. - In addition, the Relational DAS makes use of the PDO extension to - isolate itself from specifics of different back-end relational databases. - In order to use the Relational DAS you will need to be able to - create and pass a PDO database connection; - for this reason you might also want to take a look at - <link linkend='ref.pdo'>the section on PDO</link>. - </para> - - <para> - The job of the Relational DAS is to move data between the application - and a relational database. In order to do this it needs to be told - the mapping between the database entities - - tables, columns, primary keys and foreign keys - - and the elements of the SDO model - - types, properties, containment relationships and so on. - You specify this information as metadata when you - construct the Relational DAS. - </para> - - <procedure xml:id='overview'> - <title>Overview of Operation</title> - <step> - <para> - The first step is to call the Relational DAS's constructor, - passing the metadata that defines the mapping between - database and SDO model. - There are examples of this below. - </para> - </step> - - <step> - <para> - The next step might be to call the - <function>executeQuery</function> - or - <function>executePreparedQuery</function> - methods on the Relational DAS, passing either a literal SQL statement - for the DAS to prepare and execute, or a prepared statement with - placeholders and a list of values to be inserted. - You may also need to specify a small amount of metadata - about the query itself, so that the Relational DAS knows - exactly what columns will be returned from the database and - in what order. You will also need to pass a PDO database connection. - </para> - - <para> - The return value from - <function>executeQuery</function> - or - <function>executePreparedQuery</function> - is a normalised data graph containing all the data from the result set. - For a query that returns data obtained from a number of tables, - this graph will contain a number of data objects, - linked by SDO containment relationships. - There may also be SDO non-containment references within the data. - </para> - - <para> - Once the query has been executed and the data graph constructed, - there is no need for either that instance of the the Relational DAS or - the database connection. There are no locks held on the database. - Both the Relational DAS and the PDO database connection can be - garbage collected. - </para> - </step> - <step> - <para> - Quite possibly the data in the data graph will go through - a number of modifications. The data graph can be serialised - into the PHP session and so may have a lifetime beyond just - one client-server interaction. Data objects can be created - and added to the graph, the data objects already in the graph - can be deleted, and data objects in the graph can be modified. - </para> - </step> - <step> - <para> - Finally, the changes made to the data graph can be applied - back to the database using the - <function>applyChanges</function> - method of the Relational DAS. For this, another instance - of the Relational DAS must be constructed, using the - same metadata, and another connection to the database obtained. - The connection and the data graph are passed to - <function>applyChanges</function>. - At this point the Relational DAS examines the change summary - and generates the necessary INSERT, UPDATE and DELETE SQL statements - to apply the changes. Any UPDATE and DELETE statements are qualified - with the original values of the data so that should the data have - changed in the database in the meantime this will be detected. - Assuming no such collisions have occurred the changes will be - committed to the database. The application can then continue to work - with the data graph, make more changes and apply them, or can discard - it. - </para> - </step> - </procedure> - <para> - There are other ways of working with the data in the database: - it is possible to just create data objects and write them to the - database without a preliminary call to - <function>executeQuery</function>, - for example. This scenario and others are explored in the - <link linkend="sdo.das.rel.examples">Examples</link> - section below. - </para> - </section> <!-- intro --> - - <section xml:id="sdo.das.rel.installation"> - &reftitle.install; - <para> - The installation instructions for all the SDO components - are in the SDO - <link linkend="sdo.installation">install</link> - section of the SDO documentation. - </para> - <para> - In any case, the essential facts are that - the Relational DAS is written in PHP and it - should be placed somewhere on the PHP - <link linkend="ini.include-path">include_path</link> - . - </para> - - <para> - Your application will of course need to include the Relational DAS - with a statement like this: - <programlisting role="php"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -?> -]]> - </programlisting> - </para> - </section> - - <section xml:id="sdo.das.rel.requirements"> - &reftitle.required; - <para> - The Relational DAS requires that the SDO extension be installed. - The SDO extension requires a version of PHP 5.1, and the - Relational DAS requires a recent version that contains - an important fix for PDO. The most up-to-date information about - required levels of PHP should be found in the changelog for the - package on PECL. At the time of writing, though, the Relational - DAS requires the most recent beta level of PHP 5.1, that is - PHP 5.1.0. - </para> - <para> - The Relational DAS uses PDO to access the relational database, - and so should run with a variety of different relational databases. - At the time of writing it has been tested in the following configurations - <itemizedlist> - <listitem> - <para> - MySQL 4.1.14, on Windows. - The Relational DAS operates correctly with the php_pdo_mysql - driver that comes with the pre-built binaries for PHP 5.1.0. - </para> - </listitem> - <listitem> - <para> - MySQL 4.1.13, on Linux. It is necessary to have the most up-to-date - PDO driver for MySQL, which comes built in to PHP 5.1.0. - It may be necessary to uninstall the usual driver that would have - come from PECL using - <command>pear uninstall pdo_mysql</command> - . You will need to configure PHP with the - <command>--with-pdo-mysql</command> option. - </para> - </listitem> - <listitem> - <para> - DB2 8.2 Personal Edition, on Windows. - The Relational DAS operates correctly with the - php_pdo_odbc driver that comes with the pre-built binaries for - PHP 5.1.0. - </para> - </listitem> - <listitem> - <para> - DB2 8.2 Personal Developer's Edition, on Linux. - The Developer's Edition is needed because it - contains the include files needed when PHP is configured - and built. You will need to configure PHP with the - <command>--with-pdo-odbc=ibm-db2</command> option. - </para> - </listitem> - </itemizedlist> - </para> - - <para> - The Relational DAS applies changes to the database within - a user-delimited transaction: that is, it issues a call to - <function>PDO::beginTransaction</function> - before beginning to apply changes, and - <function>PDO::commit</function> - or - <function>PDO::rollback</function> - on completion. - Whichever database is chosen, the database and the PDO driver - for the database must support these calls. - </para> - </section> - - <section xml:id="sdo.das.rel.limitations"> - <title>Limitations</title> - <para> - There are the following limitations in the current release of the - Relational DAS: - <itemizedlist> - <listitem> - <para> - No support for nulls. There is no support for SQL NULL type. - It is not legal to assign PHP NULL to a data object property - and the Relational DAS will not write that back as a NULL to the - database. If nulls are found in the database on a query, - the property will remain unset. - </para> - </listitem> - <listitem> - <para> - Only two types of SDO relationship. The metadata described below - allows the Relational DAS to model just two types of SDO relationship: - multi-valued containment relationships and single-valued - non-containment references. In SDO, whether a property describes a - single- or multi-valued relationship, and whether it is containment - or non-containment, are independent. The full range of possibilities - that SDO allows cannot all be defined. There may be relationships - that it would be useful to model but which the current implementation - cannot manage. - One example is a single-valued containment relationship. - </para> - </listitem> - <listitem> - <para> - No support for the full range of SDO data types. The Relational - DAS defines all primitive properties in the SDO model as being - of type string. SDO defines a richer set of types containing various - integer, float, boolean and data and time types. String is adequate - for the purposes of the Relational DAS since the combination of PHP, - PDO and the database will ensure that values passed as strings - will be converted to the proper type before being put in the database. - This does affect some scenarios in which the Relational DAS has - to work with a data graph that has come from or will go to a - different DAS. - </para> - </listitem> - <listitem> - <para> - Only one foreign key per table. - The metadata only provides the means to specify one foreign key - per table. This foreign key may be mapped to one of the two types of - SDO relationship supported. Obviously there are some scenarios - that cannot be described under this limitation - it is not possible - to have two non-containment references from one table to another - for example. - </para> - </listitem> - </itemizedlist> - </para> - </section> - - <section xml:id='sdo.das.rel.examples'> - &reftitle.examples; - <para> - This section illustrates how the Relational DAS can be used to create, - retrieve, update and delete data in a relational database. - Many of the examples are illustrated with a three-table database that - contains companies, departments within those companies, and employees - that work in those departments. This example is used in a number of - places within the SDO literature. See the examples section of the - <link xlink:href='&url.ibm.sdo.spec;'>Service Data Objects specification</link> - or the - <link linkend="sdo.examples">Examples</link> - section of the documentation for the SDO extension. - </para> - - <para> - The Relational DAS is constructed with metadata that defines the - relational database and how it should be mapped to SDO. - The long section that follows describes this metadata and how to - construct the Relational DAS. The examples that follow it all assume that - this metadata is in an included php file. - </para> - - <para> - The examples below and others can all be found in the - <filename>Scenarios</filename> - directory in the Relational DAS package. - </para> - - <para> - The Relational DAS throws exceptions in the event that it finds errors - in the metadata or errors when executing SQL statements against the - database. For brevity the examples below all omit the use of try/catch - blocks around the calls to the Relational DAS. - </para> - - <para> - These examples all differ from the expected use of SDO in two - important respects. - </para> - <para> - First, they show all interactions with the database completed within - one script. In this respect these scenarios are not realistic but are - chosen to illustrate just the use of the Relational DAS. - It is expected that interactions with the database will be separated - in time and the data graph serialised and deserialised into the PHP - session one or more times as the application interacts with an end user. - </para> - <para> - Second, all queries executed against the database use hard-coded - queries with no variables substituted. In this case it is safe to - use the simple - <function>executeQuery</function> - call, and this is what the examples illustrate. - In practice, though, it is unlikely that the SQL statement is known - entirely ahead of time. In order to allow variables to be safely - substituted into the SQL queries, without running the risk of - injecting SQL with unknown effects, it is safer to use the - <function>executePreparedQuery</function> - which takes a prepared SQL statement containing placeholders - and a list of values to be substituted. - </para> - - <section xml:id='sdo.das.rel.metadata'> - <title>Specifying the metadata</title> - <para> - This first long section describes in detail how the metadata describing - the database and the required SDO model is supplied to the - Relational DAS. - </para> - <para> - When the constructor for the Relational DAS is invoked, it needs to be - passed several pieces of information. The bulk of the information, - passed as an associative array in the first argument to the constructor, - tells the Relational DAS what it needs to know about the relational - database. It describes the names of the tables, columns, primary keys - and foreign keys. It should be fairly easy to understand what is - required, and once written it can be placed in a php file and included - when needed. The remainder of the information, passed in the second - and third arguments to the constructor, tells the Relational DAS what - it needs to know about the relationships between objects and the shape - of the data graph; it ultimately determines how the data from the - database is to be normalised into a graph. - </para> - - <section xml:id='sdo.das.rel.metadata.database'> - <title>Database metadata</title> - <para> - The first argument to the constructor describes the target - relational database. - </para> - - <para> - Each table is described by an associative array with up to four keys. - <informaltable> - <tgroup cols='2'> - <thead> - <row> - <entry>Key</entry> - <entry>Value</entry> - </row> - </thead> - <tbody> - <row> - <entry>name</entry> - <entry>The name of the table.</entry> - </row> - <row> - <entry>columns</entry> - <entry> - An array listing the names of the columns, in any order. - </entry> - </row> - <row> - <entry>PK</entry> - <entry>The name of the column containing the primary key.</entry> - </row> - <row> - <entry>FK</entry> - <entry>An array with two entries, 'from' and 'to', which define - a column containing a foreign key, and a table to which the foreign - key points. If there are no foreign keys in the table then the - 'FK' entry does not need to be specified. Only one foreign key - can be specified. Only a foreign key pointing to the primary key - of a table can be specified. - </entry> - </row> - </tbody> - </tgroup> - </informaltable> - </para> - - <programlisting role="php"> -<![CDATA[ -<?php -/***************************************************************** -* METADATA DEFINING THE DATABASE -******************************************************************/ -$company_table = array ( - 'name' => 'company', - 'columns' => array('id', 'name', 'employee_of_the_month'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'employee_of_the_month', - 'to' => 'employee', - ), - ); -$department_table = array ( - 'name' => 'department', - 'columns' => array('id', 'name', 'location', 'number', 'co_id'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'co_id', - 'to' => 'company', - ) - ); -$employee_table = array ( - 'name' => 'employee', - 'columns' => array('id', 'name', 'SN', 'manager', 'dept_id'), - 'PK' => 'id', - 'FK' => array ( - 'from' => 'dept_id', - 'to' => 'department', - ) - ); -$database_metadata = array($company_table, $department_table, $employee_table); -?> -]]> - </programlisting> - - <para> - This metadata corresponds to a relational database that might have - been defined to MySQL as: - </para> - <programlisting role="sql"> -<![CDATA[ - create table company ( - id integer auto_increment, - name char(20), - employee_of_the_month integer, - primary key(id) - ); - create table department ( - id integer auto_increment, - name char(20), - location char(10), - number integer(3), - co_id integer, - primary key(id) - ); - create table employee ( - id integer auto_increment, - name char(20), - SN char(4), - manager tinyint(1), - dept_id integer, - primary key(id) - ); -]]> - </programlisting> - <para> - or to DB2 as: - </para> - <programlisting role="sql"> -<![CDATA[ -create table company ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - employee_of_the_month integer, \ - primary key(id) ) -create table department ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - location varchar(10), \ - number integer, \ - co_id integer, \ - primary key(id) ) -create table employee ( \ - id integer not null generated by default as identity, \ - name varchar(20), \ - SN char(4), \ - manager smallint, \ - dept_id integer, \ - primary key(id) ) -]]> - </programlisting> - - <para> - Note that although in this example there are no foreign keys specified - to the database and so the database is not expected to enforce - referential integrity, the intention behind the - <varname>co_id</varname> - column on the department table and the - <varname>dept_id</varname> - column on the employee table is they should contain the primary key - of their containing company or department record, respectively. - So these two columns are acting as foreign keys. - </para> - - <para> - There is a third foreign key in this example, that from the - <varname>employee_of_the_month</varname> - column of the company record to a single row of the employee table. - Note the difference in intent between this foreign key and the other - two. The - <varname>employee_of_the_month</varname> - column represents a single-valued relationship: there can be only - one employee of the month for a given company. - The - <varname>co_id</varname> - and - <varname>dept_id</varname> - columns represent multi-valued relationships: a company can contain - many departments and a department can contain many employees. - This distinction will become evident when the remainder of the metadata - picks out the company-department and department-employee relationships - as containment relationships. - </para> - - <para> - There are a few simple rules to be followed when constructing the - database metadata: - </para> - - <itemizedlist> - <listitem> - <para> - All tables must have primary keys, and the primary keys must be - specified in the metadata. Without primary keys it is not possible - to keep track of object identities. As you can see from the SQL - statements that create the tables, primary keys can be - auto-generated, that is, generated and assigned by the database when - a record is inserted. In this case the auto-generated primary key - is obtained from the database and inserted into the data object - immediately after the row is inserted into the database. - </para> - </listitem> - - <listitem> - <para> - It is not necessary to specify in the metadata all the columns - that exist in the database, only those that will be used. - For example, if the company table had another column that the - application did not want to access with SDO, this need not be - specified in the metadata. On the other hand it would have done - no harm to specify it: if specified in the metadata but never - retrieved, or assigned to by the application, then the unused column - will not affect anything. - </para> - </listitem> - - <listitem> - <para> - In the database metadata note that the foreign key definitions - identify not the destination column in the table which is pointed - to, but the table name itself. Strictly, the relational model - permits the destination of a foreign key to be a non-primary key. - Only foreign keys that point to a primary key are useful for - constructing the SDO model, so the metadata specifies the table name. - It is understood that the foreign key points to the primary key of - the given table. - </para> - </listitem> - </itemizedlist> - - <para> - Given these rules, and given the SQL statements that define the - database, the database metadata should be easy to construct. - </para> - - <section xml:id='sdo.das.rel.metadata.database.model'> - <title>What the Relational DAS does with the metadata</title> - <para> - The Relational DAS uses the database metadata to form most of the - SDO model. For each table in the database metadata, an SDO type - is defined. Each column which can represent a primitive value - (columns which are not defined as foreign keys) are added - as properties to the SDO type. - </para> - <para> - All primitive properties are given a type of string in the SDO model, - regardless of their SQL type. When writing values back to the - database the Relational DAS will create SQL statements that treat - the values as strings, and the database will convert them to the - appropriate type. - </para> - - <para> - Foreign keys are interpreted in one of two ways, depending on the - metadata in the third argument to the constructor that defines - the SDO containment relationships. - A discussion of this is therefore deferred until the section on - <link linkend="sdo.das.rel.metadata.crels"> - SDO containment relationships - </link> - below. - </para> - </section> - </section> - - <section xml:id='sdo.das.rel.metadata.approottype'> - <title>Specifying the application root type</title> - <para> - The second argument to the constructor is the application root type. - The true root of each data graph is an object of a special root type - and all application data objects come somewhere below that. Of the - various application types in the SDO model, one has to be the - application type immediately below the root of the data graph. - If there is only one table in the database metadata, the application - root type can be inferred, and this argument can be omitted. - </para> - </section> - - <section xml:id='sdo.das.rel.metadata.crels'> - <title>Specifying the SDO containment relationships</title> - - <para> - The third argument to the constructor defines how the types in the - model are to be linked together to form a graph. It identifies the - parent-child relationships between the types which collectively form a - graph. The relationships need to be supported by foreign keys to be - found in the data, in a way shortly to be described. - </para> - - <para> - The metadata is an array containing one or more associative arrays, - each of which identifies a parent and a child. The example below shows - a parent-child relationship from company to department, and another - from department to employee. Each of these will become an SDO property - defining a multi-valued containment relationship in the SDO model. - - </para> - <programlisting role="php"> -<![CDATA[ -<?php -$department_containment = array( 'parent' => 'company', 'child' => 'department'); -$employee_containment = array( 'parent' => 'department', 'child' => 'employee'); - -$SDO_containment_metadata = array($department_containment, $employee_containment); -?> -]]> - </programlisting> - - <para> - Foreign keys in the database metadata are interpreted as properties - with either multi-valued containment relationships or single-valued - non-containment references, depending on whether they have a - corresponding SDO containment relationship specified in the metadata. - In the example here, the foreign keys from department to company (the - <varname>co_id</varname> - column in the department table) - and from employee to department (the - <varname>dept_id</varname> - column in the employee table) are interpreted as supporting the - SDO containment relationships. - Each containment relationship mentioned in the SDO containment relationships - metadata must have a corresponding foreign key present in the - database and defined in the database metadata. The values of the - foreign key columns for containment relationships do not appear in the - data objects, instead each is represented by a containment relationship - from the parent to the child. So the - <varname>co_id</varname> - column in the department row in the database, for example, does not - appear as a property on the department type, but instead as a - containment relationship called - <varname>department</varname> - on the company type. - Note that the foreign key and the parent-child relationship appear to - have opposite senses: the foreign key points from the department to - the company, but the parent-child relationship points from company to - department. - </para> - - <para> - The third foreign key in this example, the - <varname>employee_of_the_month</varname> - , - is handled differently. - This is not mentioned in the SDO containment relationships metadata. - As a consequence this is interpreted in the second way: it becomes - a single-valued non-containment reference on the company object, to - which can be assigned references to SDO data objects of the employee - type. It does appear as a property on the company type. The way to - assign a value to it in the SDO data graph is to have a graph that - contains an employee object through the containment relationships, and - to assign the object to it. This is illustrated in the later examples - below. - </para> - </section> - </section> <!--specifying the metadata --> - - <section xml:id='sdo.das.rel.examples.one-table'> - <title>One-table examples</title> - <para> - The following set of examples all use the Relational DAS to work with - a data graph containing just one application data object, a single - company and the data just to be found the company table. These examples - do not exercise the power of SDO or the Relational DAS and of course - the same result could be achieved more economically with direct SQL - statements but they are intended to illustrate how to work with the - Relational DAS. - </para> - - <para> - For this very simple scenario it would be possible to simplify the - database metadata to include just the company table - if that were done - the second and third arguments to the constructor and the column - specifier used in the query example would become optional. - </para> - - <para> - <example> - <title>Creating a data object</title> - <para> - The simplest example is that of creating a single data object and - writing it to the database. In this example a single company object - is created, its name is set to 'Acme', and the Relational DAS is - called to write the changes to the database. The company name is - set here using the property name method. See the - <link linkend="sdo.examples">Examples</link> - section on the SDO extension for other ways of accessing the - properties of an object. - </para> - - <para> - Data objects can only be created when you have a data object to - start with, however. It is for that reason that the first call - to the Relational DAS here is to obtain a root object. This is - in effect how to ask for an empty data graph - the special root - object is the true root of the tree. The company data object is - then created with a call to - <function>createDataObject</function> - on the root object. This creates the company data object and inserts - it in the graph by inserting into a multi-valued containment property - on the root object called 'company'. - </para> - <para> - When the Relational DAS is called to apply the changes a simple - insert statement 'INSERT INTO company (name) VALUES ("Acme");' - will be constructed and executed. The auto-generated primary key - will be set into the data object and the change summary will be reset, - so that it would be possible to continue working with the same data - object, modify it, and apply the newer changes a second time. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Obtain a root object and create a company object underneath. - * Make a simple change to the data object. - ***************************************************************/ -$root = $das -> createRootDataObject(); -$acme = $root -> createDataObject('company'); - -$acme->name = "Acme"; - -/************************************************************** - * Get a database connection and write the object to the database - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das -> applyChanges($dbh, $root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Retrieving a data object</title> - <para> - In this example a single data object is retrieved from the database - - or possibly more than one if there is more than one company - called 'Acme'. For each company returned, the - <varname>name</varname> - and - <varname>id</varname> - properties are echoed. - </para> - <para> - In this example the third argument to - <function>executeQuery</function>, - the column specifier is needed as there are other tables in the - metadata with column names of - <varname>name</varname> - and - <varname>id</varname>. - If there were no possible ambiguity it could be omitted. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-R"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme"', - array('company.name', 'company.id') ); - -/************************************************************** - * Echo name and id - ***************************************************************/ -foreach ($root['company'] as $company) { - echo "Company obtained from the database has name = " . - $company['name'] . " and id " . $company['id'] . "\n"; -} -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Updating a data object</title> - <para> - This example combines the previous two, in the sense that in order - to be updated the object must first be retrieved. The application - code reverses the company name (so 'Acme' becomes 'emcA') and then the - changes are written back to the database in the same way that they - were when the object was created. Because the query searches for - the name both ways round the program can be run repeatedly to find - the company and reverse its name each time. - </para> - <para> - In this example the same instance of the Relational DAS is reused - for the - <function>applyChanges</function>, - as is the PDO database handle. This is quite alright; it also - alright to allow the previous instances to be garbage collected - and to obtain new instances. No state data regarding the graph - is held the Relational DAS once it has returned a data graph to - the application. All necessary data is either within the graph itself, - or can be reconstructed from the metadata. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme" or name="emcA"', - array('company.name', 'company.id') ); - -/************************************************************** - * Alter the name of just the first company - ***************************************************************/ -$company = $root['company'][0]; -echo "obtained a company with name of " . $company->name . "\n"; -$company->name = strrev($company->name); - -/************************************************************** - * Write the change back - ***************************************************************/ -$das->applyChanges($dbh,$root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>Deleting a data object</title> - <para> - Any companies called 'Acme' or its reverse 'emcA' are retrieved. - They are then all deleted from the graph with unset. - </para> - - <para> - In this example they are all deleted in one go by unsetting the - containing property (the property defining the containment - relationship). It is also possible to delete them individually. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1c-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Construct the DAS with the metadata - ***************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -/************************************************************** - * Get a database connection - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -/************************************************************** - * Issue a query to obtain a company object - possibly more if they exist - ***************************************************************/ -$root = $das->executeQuery($dbh, - 'select name, id from company where name="Acme" or name="emcA"', - array('company.name', 'company.id') ); - -/************************************************************** - * Delete any companies found from the data graph - ***************************************************************/ -unset($root['company']); - -/************************************************************** - * Write the change(s) back - ***************************************************************/ -$das->applyChanges($dbh,$root); -?> -]]> - </programlisting> - </example> - </para> - - </section> <!-- one-table --> - - <section xml:id='sdo.das.rel.examples.two-table'> - <title>Two-table examples</title> - <para> - The following set of examples all use two tables from the company - database: the company and department tables. These examples exercise - more of the function of the Relational DAS. - </para> - <para> - In this series of examples a company and department are created, - retrieved, updated, and finally deleted. This illustrates the - lifecycle for a data graph containing more than one object. Note that - this example clears out the company and department tables at the start - so that the exact results of the queries can be known. - </para> - <para> - You can find these examples combined into one script called - <filename>1cd-CRUD</filename> - in the - <filename>Scenarios</filename> - directory in the Relational DAS package. - </para> - - <para> - <example> - <title>One company, one department - Create</title> - <para> - As in the earlier example of creating just one company data object, - the first action after constructing the Relational DAS is to call - <function>createRootDataObject</function> - to obtain the special root object of the otherwise empty data graph. - The company object is then created as a child of the root object, - and the department object as a child of the company object. - </para> - <para> - When it comes to applying the changes, the Relational DAS has to - perform special processing to maintain the foreign keys that support - the containment relationships, especially if auto-generated primary - keys are involved. In this example, the relationship between the - auto-generated primary key - <varname>id</varname> - in the company table and the - <varname>co_id</varname> - column in the department table must be maintained. When inserting a - company and department for the first time the Relational DAS has to - first insert the company row, then call PDO's - <function>getLastInsertId</function> - method to obtain the auto-generated primary key, then add that as - the value of the - <varname>co_id</varname> - column when inserting the department row. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* -* Empty out the two tables -*************************************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$pdo_stmt = $dbh->prepare('DELETE FROM COMPANY;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM DEPARTMENT;'); -$rows_affected = $pdo_stmt->execute(); - -/************************************************************** -* Create a company with name Acme and one department, the Shoe department -***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das -> createRootDataObject(); - -$acme = $root -> createDataObject('company'); -$acme -> name = "Acme"; - -$shoe = $acme->createDataObject('department'); -$shoe->name = 'Shoe'; - -$das -> applyChanges($dbh, $root); - -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, one department - Retrieve and Update</title> - - <para> - In this case the SQL query passed to - <function>executeQuery</function> - performs an inner join to join the data from the company - and department tables. Primary keys for both the company and - department tables must be included in the query. The result set - is re-normalised to form a normalised data graph. Note that a - column specifier is passed as the third argument to the - <function>executeQuery</function> - call enabling the Relational DAS to know which column is which in - the result set. - </para> - <para> - Note that the - <varname>co_id</varname> - column although used in the query is not needed in the result set. - In order to understand what the Relational DAS is doing when it builds - the data graph it may be helpful to visualise what the result set - looks like. Although the data in the database is normalised, so that - multiple department rows can point through their foreign key to one - company row, the data in the result set is non-normalised: that is, - if there is one company and multiple departments, the values for the - company are repeated in each row. The Relational DAS has to reverse - this process and turn the result set back into a normalised data graph, - with just one company object. - </para> - <para> - In this example the Relational DAS will examine the result set and - column specifier, find data for both the company and department - tables, find primary keys for both, and interpret each row as - containing data for a department and its parent company. If it has - not seen data for that company before (it uses the primary key to - check) it creates a company object and then a department object - underneath it. If it has seen data for that company before and - has already created the company object it just creates the - department object underneath. - </para> - - <para> - In this way the Relational DAS can retrieve and renormalise data - for multiple companies and multiple departments underneath them. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Retrieve the company and Shoe department, then delete Shoe and add IT - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das->executeQuery($dbh, -'select c.id, c.name, d.id, d.name from company c, department d where d.co_id = c.id', -array('company.id','company.name','department.id','department.name')); - -$acme = $root['company'][0]; // get the first company - will be 'Acme' -$shoe = $acme['department'][0]; // get the first department underneath - will be 'Shoe' - -unset($acme['department'][0]); - -$it = $acme->createDataObject('department'); -$it->name = 'IT'; - -$das -> applyChanges($dbh, $root); -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, two departments - Retrieve and Delete</title> - <para> - In this example the company and department are retrieved and - then deleted. It is not necessary to delete them individually - (although that would be possible) - deleting the company object - from the data graph also deletes any departments underneath it. - </para> - <para> - Note the way that the company object is actually deleted using the - PHP unset call. The unset has to be performed on the containing - property which in this case is - the company property on the special - root object. You must use: - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-CRUD.good-delete"> -<![CDATA[ -<?php -unset($root['company'][0]); -?> -]]> - </programlisting> - and not: - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-CRUD.bad-delete"> -<![CDATA[ -<?php -unset($acme); //WRONG -?> -]]> - </programlisting> - Simply unsetting - <varname>$acme</varname> - would destroy the variable but leave the data in the data - graph untouched. - </para> - - <programlisting role="php" xml:id="sdo.das.rel.examples.1cd-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************** - * Retrieve the company and IT department, then delete the whole company - ***************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); - -$root = $das->executeQuery($dbh, -'select c.id, c.name, d.id, d.name from company c, department d where d.co_id = c.id', -array('company.id','company.name','department.id','department.name')); - -$acme = $root['company'][0]; -$it = $acme['department'][0]; - -unset($root['company'][0]); - -$das -> applyChanges($dbh, $root); - -?> -]]> - </programlisting> - </example> - </para> - </section> - - <section xml:id='sdo.das.rel.examples.three-table'> - <title>Three-table example</title> - <para> - The following examples use all three tables from the company database: - the company, department, and employee tables. These introduce the final - piece of function not exercised by the examples above: the - non-containment reference - <varname>employee_of_the_month</varname>. - </para> - <para> - Like the examples above for company and department, this set of examples - is intended to illustrate the full lifecycle of such a data graph. - </para> - - - <para> - <example> - <title>One company, one department, one employee - Create</title> - <para> - In this example a company is created containing one department and - just one employee. Note that this example clears out all three tables - at the start so that the exact results of the queries can be known. - </para> - <para> - Note how once the company, department and employee have been created, - the - <varname>employee_of_the_month</varname> - property of the company can be made to point at the new employee. - As this is a non-containment reference, this cannot be done until - the employee object has been created within the graph. - Non-containment references need to be managed carefully. - For example if the employee were now deleted from under the department, - it would not be correct to try to save the graph without - first clearing or re-assigning the - <varname>employee_of_the_month</varname> - property. - The closure rule for SDO data graphs requires that any object pointed - at by a non-containment reference must also be reachable by - containment relationships. - </para> - <para> - When it comes to inserting the graph into the database, the procedure - is similar to the example of inserting the company and department, - but - <varname>employee_of_the_month</varname> - introduces an extra complexity. - The Relational DAS needs to insert the objects working down the tree - formed by containment relationships, so company, then department, then - employee. This is necessary so that it always has the auto-generated - primary key of a parent on hand to include in a child row. But when - the company row is inserted the employee who is employee of the month - has not yet been inserted and the primary key is not known. The - procedure is that after the employee record is inserted and its - primary key known, a final step is performed in which the the - company record is updated with the employee's primary key. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-C"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* -* Empty out the three tables -*************************************************************************************/ -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); -$pdo_stmt = $dbh->prepare('DELETE FROM COMPANY;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM DEPARTMENT;'); -$rows_affected = $pdo_stmt->execute(); -$pdo_stmt = $dbh->prepare('DELETE FROM EMPLOYEE;'); -$rows_affected = $pdo_stmt->execute(); - -/************************************************************************************* -* Create a tiny but complete company. -* The company name is Acme. -* There is one department, Shoe. -* There is one employee, Sue. -* The employee of the month is Sue. -*************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das -> createRootDataObject(); -$acme = $root -> createDataObject('company'); -$acme -> name = "Acme"; -$shoe = $acme -> createDataObject('department'); -$shoe -> name = 'Shoe'; -$shoe -> location = 'A-block'; -$sue = $shoe -> createDataObject('employee'); -$sue -> name = 'Sue'; -$acme -> employee_of_the_month = $sue; - -$das -> applyChanges($dbh, $root); - -echo "Wrote back Acme with one department and one employee\n"; -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, one department, one employee - Retrieve and update</title> - <para> - The SQL statement passed to the Relational DAS is this time an inner - join that retrieves data from all three tables. Otherwise this example - introduces nothing that has not appeared in a previous example. - </para> - <para> - The graph is updated by the addition of a new department and employee - and some alterations to the name properties of the existing objects - in the graph. The combined changes are then written back. The - Relational DAS will process and apply an arbitrary mixture of - additions, modifications and deletions to and from the data graph. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-RU"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* - * Find the company again and change various aspects. - * Change the name of the company, department and employee. - * Add a second department and a new employee. - * Change the employee of the month. - *************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das->executeQuery($dbh, - "select c.id, c.name, c.employee_of_the_month, d.id, d.name, e.id, e.name " . - "from company c, department d, employee e " . - "where e.dept_id = d.id and d.co_id = c.id and c.name='Acme'", - array('company.id','company.name','company.employee_of_the_month', - 'department.id','department.name','employee.id','employee.name')); -$acme = $root['company'][0]; - -$shoe = $acme->department[0]; -$sue = $shoe -> employee[0]; - -$it = $acme->createDataObject('department'); -$it->name = 'IT'; -$it->location = 'G-block'; -$billy = $it->createDataObject('employee'); -$billy->name = 'Billy'; - -$acme->name = 'MegaCorp'; -$shoe->name = 'Footwear'; -$sue->name = 'Susan'; - -$acme->employee_of_the_month = $billy; -$das -> applyChanges($dbh, $root); -echo "Wrote back company with extra department and employee and all the names changed (Megacorp/Footwear/Susan)\n"; - -?> -]]> - </programlisting> - </example> - </para> - - <para> - <example> - <title>One company, two departments, two employees - Retrieve and delete</title> - <para> - The company is retrieved as a complete data graph containing five - data objects - the company, two departments and two employees. - They are all deleted by deleting the company object. Deleting an - object from the graph deletes all the object beneath it in the graph. - Five SQL DELETE statements will be generated and executed. As always - they will be qualified with a WHERE clause that contains all of the - fields that were retrieved, so that any updates to the data in the - database in the meantime by another process will be detected. - </para> - <programlisting role="php" xml:id="sdo.das.rel.examples.1cde-RD"> -<![CDATA[ -<?php -require_once 'SDO/DAS/Relational.php'; -require_once 'company_metadata.inc.php'; - -/************************************************************************************* - * Now read it one more time and delete it. - * You can delete part, apply the changes, then carry on working with the same graph but - * care is needed to keep closure - you cannot delete the employee who is eotm without - * reassigning. For safety here we delete the company all in one go. - *************************************************************************************/ -$das = new SDO_DAS_Relational ($database_metadata,'company',$SDO_containment_metadata); -$dbh = new PDO(PDO_DSN,DATABASE_USER,DATABASE_PASSWORD); - -$root = $das->executeQuery($dbh, - "select c.id, c.name, c.employee_of_the_month, d.id, d.name, e.id, e.name " . - "from company c, department d, employee e " . - "where e.dept_id = d.id and d.co_id = c.id and c.name='MegaCorp';", - array('company.id','company.name','company.employee_of_the_month', - 'department.id','department.name','employee.id','employee.name')); -$megacorp = $root['company'][0]; - -unset($root['company']); -$das -> applyChanges($dbh, $root); - -echo "Deleted the company, departments and employees all in one go.\n"; - -?> -]]> - </programlisting> - </example> - </para> - - - </section> - </section> - - <section xml:id='sdo.das.rel.tracing'> - <title>Tracing</title> - <para> - You may be interested in seeing the SQL statements that are generated - in order to apply changes back to the database. At the top of the - <filename>SDO/DAS/Relational.php</filename> - you will find a number of constants which control whether the process - of constructing and executing the SQL statements is to be traced. - Try setting - <varname>DEBUG_EXECUTE_PLAN</varname> - to &true; to see the generated SQL statements. - </para> - </section> + <!-- FIXME: The rest should be reworked to follow our OOskeletons --> <!-- class definition section --> <section xml:id='sdo.das.rel.classes'> &reftitle.classes; @@ -1535,11 +106,6 @@ </section> - <!-- Include the stuff from constants.xml? --> - <!-- -&reference.sdodasrel.constants; ---> - </partintro> <!-- This seems to create the table of contents --> @@ -1566,3 +132,4 @@ vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> + http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/constants.xml?r1=1.3&r2=1.3.2.1&diff_format=u Index: phpdoc/en/reference/uodbc/constants.xml diff -u phpdoc/en/reference/uodbc/constants.xml:1.3 phpdoc/en/reference/uodbc/constants.xml:1.3.2.1 --- phpdoc/en/reference/uodbc/constants.xml:1.3 Wed Jun 20 22:25:33 2007 +++ phpdoc/en/reference/uodbc/constants.xml Fri Dec 7 14:24:26 2007 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> -<section xml:id="uodbc.constants" xmlns="http://docbook.org/ns/docbook"> +<!-- $Revision: 1.3.2.1 $ --> +<appendix xml:id="uodbc.constants" xmlns="http://docbook.org/ns/docbook"> &reftitle.constants; &extension.constants; <variablelist> @@ -577,7 +577,7 @@ </listitem> </varlistentry> </variablelist> -</section> +</appendix> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/reference.xml?r1=1.12.2.1&r2=1.12.2.2&diff_format=u Index: phpdoc/en/reference/uodbc/reference.xml diff -u phpdoc/en/reference/uodbc/reference.xml:1.12.2.1 phpdoc/en/reference/uodbc/reference.xml:1.12.2.2 --- phpdoc/en/reference/uodbc/reference.xml:1.12.2.1 Wed Oct 3 11:41:16 2007 +++ phpdoc/en/reference/uodbc/reference.xml Fri Dec 7 14:24:26 2007 @@ -1,69 +1,8 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.12.2.1 $ --> -<!-- Purpose: database.abstract --> -<!-- Membership: bundled, external --> +<!-- $Revision: 1.12.2.2 $ --> <reference xml:id="ref.uodbc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>ODBC Functions (Unified)</title> - <titleabbrev>ODBC</titleabbrev> - - <partintro> - <section xml:id="uodbc.intro"> - &reftitle.intro; - <para> - In addition to normal ODBC support, the Unified ODBC functions in - PHP allow you to access several databases that have borrowed the - semantics of the ODBC API to implement their own API. Instead of - maintaining multiple database drivers that were all nearly - identical, these drivers have been unified into a single set of - ODBC functions. - </para> - <para> - The following databases are supported by the Unified ODBC - functions: <link xlink:href="&url.adabas;">Adabas D</link>, - <link xlink:href="&url.ibmdb2;">IBM DB2</link>, - <link xlink:href="&url.iodbc;">iODBC</link>, - <link xlink:href="&url.solid;">Solid</link>, and - <link xlink:href="&url.sybase;">Sybase SQL Anywhere</link>. - </para> - <note> - <para> - With the exception of iODBC, there is no ODBC involved when - connecting to the above databases. The functions that you - use to speak natively to them just happen to share the same - names and syntax as the ODBC functions. However, building PHP - with iODBC support enables you to use any ODBC-compliant - drivers with your PHP applications. More information on iODBC, - is available at <link xlink:href="&url.iodbc;">www.iodbc.org</link> - with the alternative unixODBC available at - <link xlink:href="&url.unixodbc;">www.unixodbc.org</link>. - </para> - </note> - </section> - - <section xml:id="uodbc.requirements"> - &reftitle.required; - <para> - To access any of the supported databases you need to have - the required libraries installed. - </para> - </section> - - &reference.uodbc.configure; - - &reference.uodbc.ini; - - <section xml:id="uodbc.resources"> - &reftitle.resources; - <para> - This extension defines two resource types: an ODBC connection identifier - and an ODBC result identifier. - </para> - </section> - - &reference.uodbc.constants; - - </partintro> &reference.uodbc.functions.entities; http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/book.xml +++ phpdoc/en/reference/dba/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/constants.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/constants.xml +++ phpdoc/en/reference/dba/constants.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/examples.xml +++ phpdoc/en/reference/dba/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dba/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dba/setup.xml +++ phpdoc/en/reference/dba/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dbx/book.xml +++ phpdoc/en/reference/dbx/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dbx/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/dbx/setup.xml +++ phpdoc/en/reference/dbx/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/book.xml +++ phpdoc/en/reference/sdo/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/examples.xml +++ phpdoc/en/reference/sdo/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/limitations.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/limitations.xml +++ phpdoc/en/reference/sdo/limitations.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdo/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdo/setup.xml +++ phpdoc/en/reference/sdo/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/book.xml +++ phpdoc/en/reference/sdodasrel/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/examples.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/examples.xml +++ phpdoc/en/reference/sdodasrel/examples.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/limitations.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/limitations.xml +++ phpdoc/en/reference/sdodasrel/limitations.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/sdodasrel/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/sdodasrel/setup.xml +++ phpdoc/en/reference/sdodasrel/setup.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/book.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/uodbc/book.xml +++ phpdoc/en/reference/uodbc/book.xml http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/uodbc/setup.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/uodbc/setup.xml +++ phpdoc/en/reference/uodbc/setup.xml