cvs: peardoc /en/package/database/db-table intro-database.xml

From: Date: Sun, 01 Jul 2007 03:15:20 +0000
Subject: cvs: peardoc /en/package/database/db-table intro-database.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-9856@lists.php.net to get a copy of this message
morse Sun Jul 1 03:15:20 2007 UTC Modified files: /peardoc/en/package/database/db-table intro-database.xml Log: i) Fixed links ii) Added <function> tags as appropriate

http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/db-table/intro-database.xml?r1=1.4&r2=1.5&diff_format=u Index: peardoc/en/package/database/db-table/intro-database.xml diff -u peardoc/en/package/database/db-table/intro-database.xml:1.4 peardoc/en/package/database/db-table/intro-database.xml:1.5 --- peardoc/en/package/database/db-table/intro-database.xml:1.4 Sat Jun 30 03:09:22 2007 +++ peardoc/en/package/database/db-table/intro-database.xml Sun Jul 1 03:15:20 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="package.database.db-table.intro-database"> <refnamediv> @@ -96,17 +96,25 @@ </para> <para> -Like DB_Table, <classname>DB_Table_Database</classname> wraps a DB or MDB2 database connection -object. The class is compatible with both PHP 4 and PHP 5, with the -exception of one non-essential method: The +Like <classname>DB_Table</classname>, <classname>DB_Table_Database</classname> +wraps a DB or MDB2 database connection object. The class is compatible with +both PHP 4 and PHP 5, with the exception of one non-essential method: The <link linkend="package.database.db-table.intro-database.xml"> -<function>fromXML</function> +<function>fromXML</function> </link> method, which creates a <classname>DB_Table_Database</classname> object from an XML database schema, requires PHP 5. </para> <para> +Class <classname>DB_Table_Database</classname> extends abstract base class +<classname>DB_Table_Base</classname>. Methods or properties that are inherited +from <classname>DB_Table_Base</classname> are noted as such, and are indicated +in the table of contents of this page with the notation +"(from <classname>DB_Table_Base</classname>)". +</para> + +<para> This tutorial uses an extended example to introduce the use of the <classname>DB_Table_Database</classname> class to create a model of an interface to a relational database. @@ -143,52 +151,49 @@ </listitem> <listitem> <simpara> - <link -linkend="package.database.db-table.intro-database.model.delete">Deleting Tables, References, or Links</link> + <link linkend="package.database.db-table.intro-database.model.delete"> + Deleting Tables, References, or Links + </link> </simpara> </listitem> </itemizedlist> </listitem> <listitem> <simpara> - <link linkend="package.database.db-table.intro-database.refAction">Referentially Triggered Actions</link> + <link linkend="package.database.db-table.intro-database.refAction"> + Referentially Triggered Actions + </link> </simpara> <itemizedlist> <listitem> <simpara> - <link -linkend="package.database.db-table.intro-database.refAction.addRef">Declaring -actions in <function>addRef</function></link> + <link linkend="package.database.db-table.intro-database.refAction.addRef"> + Declaring actions with <function>addRef</function> + </link> </simpara> </listitem> <listitem> <simpara> - <link -linkend="package.database.db-table.intro-database.refAction.modifyRefOptions"> -<function>setOnDelete</function> and <function>setOnUpdate</function></link> + <link linkend="package.database.db-table.intro-database.refAction.modifyRefOptions"> + <function>setOnDelete</function> and <function>setOnUpdate</function> + </link> </simpara> </listitem> <listitem> - <simpara><link - linkend="package.database.db-table.intro-database.refAction.setActOn"> - <function>setActOnDelete</function> and - <function>setActOnUpdate</function></link></simpara> + <simpara> + <link linkend="package.database.db-table.intro-database.refAction.setActOn"> + <function>setActOnDelete</function> and + <function>setActOnUpdate</function> + </link> + </simpara> </listitem> </itemizedlist> </listitem> <listitem> <simpara> - <link linkend="package.database.db-table.intro-database.FKeyCheck">Checking Foreign Key Validity</link> + <link linkend="package.database.db-table.intro-database.FKeyCheck"> + Foreign Key Validation</link> </simpara> - <itemizedlist> - <listitem> - <simpara> - <link - linkend="package.database.db-table.intro-database.FKeyCheck.setCheckFKey"> - <function>setCheckFKey</function></link> - </simpara> - </listitem> - </itemizedlist> </listitem> <listitem> <simpara> @@ -209,7 +214,7 @@ <function>select</function>, <function>selectResult</function>, and <function>selectCount</function> </link> - (from DB_Table_Base) + (from <classname>DB_Table_Base</classname>) </simpara> </listitem> <listitem> @@ -236,14 +241,14 @@ <simpara> <link linkend="package.database.db-table.intro-database.util.buildFilter"> <function>buildFilter</function></link> - (from DB_Table_Base) + (from <classname>DB_Table_Base</classname>) </simpara> </listitem> <listitem> <simpara> <link linkend="package.database.db-table.intro-database.util.buildSQL"> <function>buildSQL</function></link> - (from DB_Table_Base) + (from <classname>DB_Table_Base</classname>) </simpara> </listitem> <listitem> @@ -304,9 +309,10 @@ Throughout this tutorial, our examples will refer to a <classname>DB_Table_Database</classname> object for an example database named TestDB, which is described below. -The child <classname>DB_Table</classname> objects that are associated with RDBMS tables must -all be instantiated first, and then added to (i.e., linked with) a -parent <classname>DB_Table_Database</classname> object. +The child <classname>DB_Table</classname> objects that are associated +with RDBMS tables must all be instantiated first, and then added to +(i.e., linked with) a parent <classname>DB_Table_Database</classname> +object. </para> <para> The example database TestDB stores names, numbers, and addresses @@ -323,17 +329,18 @@ <para> DB_Table objects must be instantiated before they can be added to -a parent <classname>DB_Table_Database</classname> instance. The usual way of creating a -DB_Table object (as discussed in the -DB_Table documentation) -is to create one subclass of <classname>DB_Table</classname> for each table, and create -one instance of each such subclass. In this tutorial, we use a -convention in which the subclass of <classname>DB_Table</classname> associated with a -database table named "Entity" is Entity_Table, and in which the -single object of this class is $Entity. +a parent <classname>DB_Table_Database</classname> instance. The usual +way of creating a <classname>DB_Table</classname> object (as discussed +in the tutorial for that class) is to create one subclass of +<classname>DB_Table</classname> for each table, and create one instance +of each such subclass. In this tutorial, we use a convention in which +the subclass of <classname>DB_Table</classname> associated with a +database table named "Entity" is Entity_Table, and in which the single +object of this class is $Entity. This is also the convention used in +code generated by the <classname>DB_Table_Generator</classname> class. </para> <para> -The following code defines a subclass Person_Table that represents a -database table Person: +The following code defines a subclass <classname>Person_Table</classname> +that represents a database table Person: <programlisting role="php"> <![CDATA[<?php require_once 'DB/Table.php' @@ -429,9 +436,9 @@ ?> ]]> </programlisting> -The PhoneType column of table Phone is used to distinguish home, work, -and cell phones, and so must have one of the 4 character values 'HOME', -'WORK' or 'CELL'. +In ths example, the PhoneType column of table Phone is used to distinguish +home, work, and cell phones, and so must have one of the 4 character values +'HOME', 'WORK' or 'CELL'. </para><para> The following code instantiates one object of each <classname>DB_Table</classname> subclass, which is associated with the corresponding table: @@ -584,8 +591,8 @@ <title>Adding Foreign Key References</title> <para> After tables have been added to a database, we can use the -<function>addRef</function> -method to add references between pairs of tables. +<function>addRef</function> method to add references between pairs +of tables. </para><para> Synopsis (simplified): <programlisting> @@ -606,7 +613,8 @@ simplified synopsis shown here does not include two more optional parameters (parameters 5 and 6) that can be used to specify 'on delete' and 'on update' actions. The full interface is presented -<link linkend="package.database.db-table.intro-database.refAction.addRef.synopsis">below</link>. +<link linkend="package.database.db-table.intro-database.refAction.addRef"> +below</link>. For example, the command: <programlisting role="php"> @@ -646,8 +654,8 @@ then the autoJoin method may use the linking table to join $table1 and $table2, if necessary. </para><para> -Method addLink declares a table to be a linking/association table for two -others. +Method <function>addLink</function> declares a table to be a +linking or association table for two others. </para><para> Synopsis: <programlisting> @@ -663,7 +671,8 @@ foreign keys that references to both of the linked tables. A link can only be added to the model after the references from the linking table to both of the linked tables have been added. The method returns true -on normal completion and a PEAR Error if an error is detected. +on normal completion and a <function>PEAR_Error</function> if an error +is detected. </para> <para> For example, the command: @@ -677,12 +686,13 @@ declares PersonPhone to be a linking table that links tables Person and Phone. </para><para> -The addLink method will not prevent one from declarating more than -one linking table for the same two linked tables. Doing so would -make the link declaration useless, however, because the autoJoin -method will fail if it needs to use a linking table to join a -pair of tables, but finds that more than one of linking table is -declared for those two tables. +The <function>addLink</function> method will not prevent one from +declarating more than one linking table for the same two linked +tables. Doing so would make the link declaration useless, however, +because the <function>autoJoin</function> method will fail if it +needs to use a linking table to join a pair of tables, but finds +that more than one of linking table is declared for those two +tables. </para><para> The command <programlisting role="php"> @@ -697,8 +707,9 @@ some databases, the easiest way to declare links may be by using the addAllLinks method to create all possible links and then using the -<link linkend="package.database.db-table.intro-database.deleteLink"> -deleteLink</link> method to delete those that are not desired. +<link linkend="package.database.db-table.intro-database.model.delete"> +<function>deleteLink</function></link> method to delete those that +are not desired. </para> <para> The database model is complete when all of the tables have been @@ -725,7 +736,7 @@ </para> <example> -<title>Database File</title> +<title>Database.php File</title> <programlisting role="php"> <![CDATA[ <?php @@ -766,7 +777,7 @@ $db->addTable($Phone); $db->addTable($PersonPhoneAssoc); -// Add auto-guessed foreign references +// Add foreign references $db->addRef('PersonPhoneAssoc', 'PersonID', 'Person'); $db->addRef('PersonPhoneAssoc', 'PhoneID', 'Phone'); $db->addRef('Person', 'AddressID', 'Address'); @@ -784,7 +795,7 @@ be created by <classname>DB_Table_Generator</classname> for an existing database with this structure. The main differences are that some lines in the auto-generated file would have to be -uncommented and/or to produce the above (<emphasis>e.g.</emphasis>, +uncommented or edited to produce the above (<emphasis>e.g.</emphasis>, the lines that define the database DSN). In this example, the call to <function>addAllLinks</function> method would correctly identify 'PersonPhoneAssoc' as a table that links 'Person' and 'Phone'. This @@ -837,7 +848,7 @@ reference, i.e., links in which $ftable is the linking table and $rtable is one of the linked tables. </para> -<para id="package.database.db-table.intro-database.deleteLink"> +<para id="package.database.db-table.intro-database.model.delete.Link"> <function>deleteLink</function> - deletes a linking table declaration </para> <para> @@ -850,8 +861,9 @@ is null or absent, all declarations of linking tables between $table1 and $table2 are deleted. If $link is present, only the declaration of $link as a linking table between $table1 and $table2 is deleted (if -one exists). The deleteLinks method may be used after the addAllLinks -to prune the resulting set of linking table declarations. +one exists). The <function>deleteLinks</function> method may be used +after the <function>addAllLinks</function> to prune the resulting set +of linking table declarations. </para> </refsect2> </refsect1> @@ -912,10 +924,10 @@ update method, in rows of Person that are referenced by rows of PersonPhone. </para> + <para> The full interface of the <function>addRef</function> method is: -<programlisting -id="package.database.db-table.intro-database.refAction.addRef.synopsis"> +<programlisting> <![CDATA[ true|PEAR_Error addRef(string $ftable, mixed $fkey, string $rtable, [mixed $rkey], [string|null $on_delete], [string|null $on_update]) ]]> @@ -965,8 +977,9 @@ </title> <para> The referentially triggered actions associated with a foreign key -reference may also be changed, or turned off, with the setOnDelete -and setOnUpdate methods. +reference may also be changed, or turned off, with the +<function>setOnDelete</function> and <function>setOnUpdate</function> +methods. </para><para> Synopses: <programlisting> @@ -1002,8 +1015,9 @@ </title> <para> PHP emulation of referentially triggered actions may be turned on or -off for the entire database by the setActOnDelete and setActOnUpdate -methods. +off for the entire database by the +<function>setActOnDelete</function> and +<function>setActOnUpdate</function> methods. </para> <para> Synopses: @@ -1152,7 +1166,7 @@ <function>selectResult</function> is: <programlisting> <![CDATA[ -mixed select*( string|array $sql_key, [string $filter], [string $order], [int $start], [int $count], [array $params]) +mixed select*( array|string $sql_key, [string $filter], [string $order], [int $start], [int $count], [array $params]) ]]> </programlisting> As discussed above, $sql_key is either a query array, or the key of @@ -1182,7 +1196,7 @@ Synopsis: <programlisting role="php"> <![CDATA[ -array autoJoin([array $cols], [array $tables], [string $filter]) +array|PEAR_Error autoJoin([array $cols], [array $tables], [string $filter]) ]]> </programlisting> Here, $cols is a sequential array of the names of the desired columns, @@ -1239,10 +1253,10 @@ AND PersonPhone.PersonID = Person.PersonID AND Person.AddressID = Address.AddressID </programlisting> -If autoJoin is passed only a set of column names, as in the above -example, it identifies the set of tables that contain those columns, -and joins those tables, plus any linking tables needed to create -many-to-many relationships. +If <function>autoJoin</function> is passed only a set of column names, +as in the above example, it identifies the set of tables that contain +those columns, and joins those tables, plus any linking tables needed +to create many-to-many relationships. </para><para> In the following example, the $cols parameter is null, but the names of the tables to be joined are specified in the $tables parameter: @@ -1321,7 +1335,7 @@ parameter $value. </para><para> Synposis: -<programlisting role="php"> +<programlisting> <![CDATA[ string quote(mixed $value) ]]> @@ -1375,21 +1389,25 @@ <title><function>buildSQL</function></title> <para> <function>buildSQL</function> - takes a query array of the form used by -the select* methods, and returns a corresponding SQL command string. It -is called internally by the select* methods. +the select* methods, and returns a corresponding SQL command string. +It is called internally by the <function>select*</function> methods. +Both <function>buildSQL</function> and the <function>select*</function> +methods are inherited from <classname>DB_Table_Base</classname>. </para> <para> -Synopsis: The interface is the same as that of the select* methods: -<programlisting role="php"> -<![CDATA[string buildSQL(array $query, [string $filter], [string $order], - [int $start], [int $count])]]> +Synopsis: The interface is similar to that of the <function>select*</function> +methods: +<programlisting> +<![CDATA[ +string|PEAR_Error buildSQL(array|string $query, [string $filter], [string $order], [int $start], [int $count]) +]]> </programlisting> -As in the select* methods, $query is the query array (the only required -parameter), $filter is an SQL logical condition that is added to the -'where' element of the query array, $order is an ORDER BY clause that -overrides the 'order' element of the query array when it is present, -and $start and $count are the first row in the result set that should -be returned, and the maximum number of rows that should be returned. +As in the <function>select*</function> methods, $query is a query array or a key +for a query array stored in the $sql property, $filter is an SQL logical condition +that is added to the 'where' element of the query array, $order is an ORDER BY clause +that overrides the 'order' element of the query array when it is present, and $start +and $count are the first row in the result set that should be returned, and the +maximum number of rows that should be returned. Only the $query argument is required. </para> </refsect2> @@ -1401,8 +1419,8 @@ </para> <para> Synopsis: -<programlisting role="php"> -<![CDATA[array validCol(string $col, [array $from])]]> +<programlisting> +<![CDATA[array|PEAR_Error validCol(string $col, [array $from])]]> </programlisting> The required parameter $col is a column name. The optional $from parameter is a sequential array of table names. @@ -1455,7 +1473,7 @@ <para> Synopses: -<programlisting role="php"> +<programlisting> <![CDATA[ true|PEAR_Error insert(string $table, array $data) true|PEAR_Error delete(string $table, [string $where]) @@ -1578,7 +1596,7 @@ directory for <classname>DB_Table</classname> subclass definitions. </para> <para> Synopsis: -<programlisting role="php"> +<programlisting> <![CDATA[void setTableSubclassPath(string $path)]]> </programlisting> Parameter $path is the path to the desired directory, without @@ -1647,7 +1665,7 @@ property for every child table in the database. These methods, which have the same names and interfaces as the corresponding <classname>DB_Table</classname> methods, are: -<programlisting role="php"> +<programlisting> <![CDATA[ void autoValidInsert(bool $flag); void autoValidUpdate(bool $flag);
« previous php.pear.doc (#9856) next »