cvs: peardoc /en/package/database/db-table intro-database.xml
| From: | David Morse | Date: | Fri, 08 Jun 2007 02:26:45 +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-9762@lists.php.net to get a copy of this message | ||
morse Fri Jun 8 02:26:45 2007 UTC
Modified files:
/peardoc/en/package/database/db-table intro-database.xml
Log:
Stylistic changes. Removed <?php ?> tags from synopses. Add <function> and
<classname> tags as appropriate.
http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/db-table/intro-database.xml?r1=1.1&r2=1.2&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.1 peardoc/en/package/database/db-table/intro-database.xml:1.2 --- peardoc/en/package/database/db-table/intro-database.xml:1.1 Tue May 29 18:42:23 2007 +++ peardoc/en/package/database/db-table/intro-database.xml Fri Jun 8 02:26:45 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.database.db-table.intro-database"> <refnamediv> @@ -376,14 +376,14 @@ Address table (defined below). </para><para> Note the assignment of a value for the $auto_inc_col property, which -is a recent addition to DB_Table: The value of $auto_inc_col is the -name of a column that is declared to be 'auto increment'. Auto -incrementing of this column is now implemented in the insert method +is a recent addition to <classname>DB_Table</classname>: The value of +$auto_inc_col is the name of a column that is declared to be 'auto increment'. +Auto incrementing of this column is now implemented in the insert method of <classname>DB_Table</classname> using DB or MDB2 sequences. </para><para> The following code uses the same method to create subclasses of -DB_Table associated with the remaining Phone, Address, and PersonPhone -tables of database TestDB: +<classname>DB_Table</classname> associated with the remaining Phone, +Address, and PersonPhone tables of database TestDB: <programlisting role="php"> <![CDATA[<?php class Address_Table extends DB_Table @@ -442,8 +442,8 @@ 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: +The following code instantiates one object of each <classname>DB_Table</classname> +subclass, which is associated with the corresponding table: <programlisting role="php"> <![CDATA[<?php $Person = new Person_Table($conn, 'Person', 'safe'); @@ -453,35 +453,37 @@ ?>]]> </programlisting> Here, because we have used the value 'safe' for the optional third -parameter of the <classname>DB_Table</classname> constructor in each statement, each table -will be created in the RDBMS only if and only if a table of that -name does not already exist in the database. +parameter of the <classname>DB_Table</classname> constructor in each +statement, each table will be created in the RDBMS only if and only +if a table of that name does not already exist in the database. </para> <para> It is recommended that constructor statements be placed in a separate -file from any of the <classname>DB_Table</classname> subclass definitions. Doing so makes it -easier to +file from any of the <classname>DB_Table</classname> subclass definitions. +Doing so makes it easier to <link linkend="package.database.db-table.intro-database.serialize"> serialize and unserialize</link> the -DB_Table and <classname>DB_Table_Database</classname> objects, because a php file in which -an instance of a <classname>DB_Table</classname> subclass is unserialized must have access -to the subclass definition, but should not include the constructor -statements. Putting each <classname>DB_Table</classname> subclass definition in a separate -file, with a name that is the same as the subclass name, also allows -the subclass definitions to be autoloaded when an object is -serialized, as discussed +<classname>DB_Table</classname> and <classname>DB_Table_Database</classname> +objects, because a php file in which an instance of a +<classname>DB_Table</classname> subclass is unserialized must have access +to the subclass definition, but should not include the constructor statements. +Putting each <classname>DB_Table</classname> subclass definition in a separate +file, with a name that is the subclass name with a .php extension, also allows +the subclass definitions to be autoloaded when an object is serialized, as +discussed <link linkend="package.database.db-table.intro-database.serialize">below</link>. </para> <para> -An alternative way to create a <classname>DB_Table</classname> object is to create an -instance of <classname>DB_Table</classname> itself, rather than of a subclass of DB_Table. -In this method, one first instantiates a generic <classname>DB_Table</classname> object, -which initially contains no information about the table schema, and -then sets the values of the public $col and $idx properties needed -to define a table schema. As an example, the following code constructs -the Person table as an instance of DB_Table: +An alternative way to create a <classname>DB_Table</classname> object is to +create an instance of <classname>DB_Table</classname> itself, rather than +of a subclass of <classname>DB_Table</classname>. In this method, one first +instantiates a generic <classname>DB_Table</classname> object, which initially +contains no information about the table schema, and then sets the values of +the public $col and $idx properties needed to define a table schema. As an +example, the following code constructs an instance of DB_Table that represents +the Person table: <programlisting role="php"> <![CDATA[<?php $Person = new DB_Table($conn, 'Person'); @@ -500,16 +502,19 @@ ?> ]]> </programlisting> -This method is valid only in recent versions of the <classname>DB_Table</classname> package -(1.5.0RC1 and greater) that contain the <classname>DB_Table_Database</classname> class. Earlier -versions of <classname>DB_Table</classname> required that <classname>DB_Table</classname> always be extended. The -only real disadvantage of using such generic <classname>DB_Table</classname> objects is that -it makes it impossible to override the methods of <classname>DB_Table</classname> to, for -example, customize the insert or update method so as to implement -business rules for a table. Generic <classname>DB_Table</classname> objects are used by the -fromXML method, which takes an XML description of a database schema -as a parameter, and returns a <classname>DB_Table_Database</classname> object in which each -of the child tables is represented by an instance of DB_Table. +This method is valid only in recent versions of the +<classname>DB_Table</classname> package (1.5.0RC1 and greater) that contain +the <classname>DB_Table_Database</classname> class. Earlier versions of +<classname>DB_Table</classname> required that <classname>DB_Table</classname> +always be extended. The only real disadvantage of using such generic +<classname>DB_Table</classname> objects is that it makes it impossible to +override the methods of <classname>DB_Table</classname> to, for example, +customize the insert or update method so as to implement business rules +for a table. Generic <classname>DB_Table</classname> objects are used by +the <function>fromXML</function> method, which takes an XML description of +a database schema as a parameter, and returns a +<classname>DB_Table_Database</classname> object in which each of the child +tables is represented by an instance of <classname>DB_Table</classname>. </para> </refsect1> @@ -544,27 +549,28 @@ <title>Building a Model</title> <para> To construct a model of a relational database, after instantiating a -set of <classname>DB_Table</classname> objects and a <classname>DB_Table_Database</classname> object, we must add -the table objects to the database object, add declarations of foreign -key references, and declare many-to-many relationships that involve -linking tables, in that order. +set of <classname>DB_Table</classname> objects and a +<classname>DB_Table_Database</classname> object, we must add the table +objects to the database object, add declarations of foreign key +references, and declare many-to-many relationships that involve linking +tables, in that order. </para> <refsect2 id="package.database.db-table.intro-database.model.addTable"> <title>Adding Tables</title> <para> -After a <classname>DB_Table</classname> object is instantiated, it can be added to the parent -database with the <function>DB_Table_Database::addTable</function> -method. The interface +After a <classname>DB_Table</classname> object is instantiated, it +can be added to the parent database with the +<function>DB_Table_Database::addTable</function> method. The interface for this method is <programlisting role="php"> <![CDATA[ true|Error addTable(object &$Table) ]]> </programlisting> -where $Table is a <classname>DB_Table</classname> object that is passed by reference. The -method returns boolean true on normal completion, and a PEAR Error -object on failure. +where $Table is a <classname>DB_Table</classname> object that is passed +by reference. The method returns boolean true on normal completion, and +a PEAR_Error object on failure. </para><para> The following code adds the four tables of our example database to the $db <classname>DB_Table_Database</classname> object: @@ -592,20 +598,21 @@ </para><para> Synopsis (simplified): <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ true|Error addRef(string $ftable, string|array $fkey, string $rtable, [string|array] $rkey] ) -?>]]> +]]> </programlisting> Here $ftable is the name of a referencing (or foreign key) table, $fkey is the foreign key, $rtable is the name of the referenced table, and $rkey is the (optional) referenced key. If the optional $rkey parameter is absent or null, the referenced key is taken by default to be the primary key of the referenced table. The foreign and referenced key values are specified -using the same syntax as that used to define indices in DB_Table: Each key +using the same syntax as that used to define indices in +<classname>DB_Table</classname>: Each key may be either a column name string, for a single-column key, or a sequential array of column names, for a multi-column key. The method returns true on -normal completion, and a PEAR Error on failure. The simplified synopsis +normal completion, and a PEAR_Error on failure. The 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 @@ -613,9 +620,11 @@ For example, the command: <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ +<?php $db->addRef('Person', 'AddressID', 'Address', 'AddressID'); -?>]]> +?> +]]> </programlisting> adds a reference from foreign key Person.AddressID of referencing table Person to the primary key Address.AddressID of referenced table Address. @@ -631,8 +640,8 @@ is defined, as required by standard SQL. </para><para> A reference between two tables can only be added after both the referencing -and referenced <classname>DB_Table</classname> objects have been instantiated and added to the -parent DB_Table_Datbase instance. +and referenced <classname>DB_Table</classname> objects have been instantiated +and added to the parent <classname>DB_Table_Datbase</classname> instance. </para> </refsect2> @@ -652,9 +661,9 @@ </para><para> Synopsis: <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ true|Error addLink(string $table1, string $table2, string $link) -?>]]> +]]> </programlisting> Here, $link is the name of a linking table that links tables named $table1 and $table2. All three parameters are required, and all must @@ -808,7 +817,7 @@ </para> <para id="package.database.db-table.intro-database.model.delete.table"> -deleteTable - deletes a table from the database model +<function>deleteTable</function> - deletes a table from the database model </para> <para> @@ -860,12 +869,12 @@ <refsect1 id="package.database.db-table.intro-database.refAction"> <title>On Delete and On Update Actions</title> <para> -<classname>DB_Table_Database</classname> optionally provides actions designed to enforce -referential integrity that are provided by ANSI SQL, but that are +<classname>DB_Table_Database</classname> optionally provides actions designed +to enforce referential integrity that are provided by ANSI SQL, but that are not provided by some popular databases (e.g., SQLite and the default -MySQL engine). <classname>DB_Table_Database</classname> offers optional PHP emulation of -referentially triggered ON DELETE and ON UPDATE actions, such as -cascading deletes (discussed here), and also optionally checks the +MySQL engine). <classname>DB_Table_Database</classname> offers optional PHP +emulation of referentially triggered ON DELETE and ON UPDATE actions, such +as cascading deletes (discussed here), and also optionally checks the validity of foreign key values before insertion or updating (discussed <link linkend="package.database.db-table.intro-database.FKeyCheck">below</link>) @@ -983,7 +992,8 @@ for that reference, i.e., either an action strings or null. A null parameter is used to indicate that no action on delete or update of rows of table $rtable. -</para><para> +</para> +<para> For example, the following code would change the 'on_update' action associated with the the reference from 'PersonPhone' to 'Person' to a 'restrict' action: @@ -1020,21 +1030,22 @@ default, PHP emulation of both ON DELETE and ON UPDATE actions is on. Calling either of these methods with a false value does not modify the values of the instance property (the $_ref property) that records -the on delete or on update actions associated with each reference: It -merely prevents PHP emulation of these actions by the DB_Table_Database -<function>delete</function> and -<function>update</function> methods. +the on delete or on update actions associated with each reference: +It merely prevents PHP emulation of these actions by the +<function>DB_Table_Database::delete</function> and +<function>DB_Table_Database::update</function> methods. </para> </refsect2> </refsect1> <refsect1 id="package.database.db-table.intro-database.FKeyCheck"> -<title>Foreign Key Validity Checks</title> +<title>Foreign Key Validation</title> <para> -By default, <classname>DB_Table_Database</classname> checks the validity of foreign key values -before inserting or updating data in a table with foreign keys. That is, -before inserting a row, or updating any foreign key column values, the -insert and update methods of <classname>DB_Table_Database</classname> actually submit a query +By default, <classname>DB_Table_Database</classname> checks the validity +of foreign key values before inserting or updating data in a table with +foreign keys. That is, before inserting a row, or updating any foreign key +column values, the <function>insert</function> and <function>update</function> +methods of <classname>DB_Table_Database</classname> actually submit a query to confirm that the inserted or updated foreign key column values correspond to values of the referenced columns of an existing row in the referenced table. By default, both methods throw an error, and do not modify the data, @@ -1043,7 +1054,7 @@ <para id="package.database.db-table.intro-database.FKeyCheck.setCheckFKey"> This checking of foreign key validity by the PHP layer may be turned on or off, for insertion or updating of any table in database, with the -FKeyCheck.setCheckFKey method. The interface of this method is: +<function>setCheckFKey</function> method. The interface of this method is: <programlisting role="php"> <![CDATA[void setCheckFKey(bool $flag);]]> </programlisting> @@ -1055,17 +1066,19 @@ <refsect1 id="package.database.db-table.intro-database.select"> <title>Data Selection</title> <para> -<classname>DB_Table_Database</classname> provides an object-oriented interface for SQL -select statements that is almost identical to that of DB_Table. +<classname>DB_Table_Database</classname> provides an object-oriented +interface for SQL select statements that is almost identical to that of +<classname>DB_Table</classname>. </para> <refsect2 id="package.database.db-table.intro-database.select.query"> <title>Query Arrays</title> <para> -As in DB_Table, queries are represented in <classname>DB_Table_Database</classname> as arrays -in which each array element represents one clause of a corresponding -SQL select statement. For example, a query for names of all people that -live on Oak Street in Anytown in our example database might be +As in <classname>DB_Table</classname>, queries are represented in +<classname>DB_Table_Database</classname> as arrays, in which array +elements represents clauses of a corresponding SQL select statement. +For example, a query for names of all people that live on Oak Street +in Anytown in our example database might be <programlisting role="php"> <![CDATA[<?php $oak = array( @@ -1077,8 +1090,10 @@ 'order' => 'Address.Building' ); ?>]]> </programlisting> -The <link linkend="package.database.db-table.intro-database.select.buildSQL">buildSQL</link> method accepts such a query array -as a parameter and returns the corresponding SQL command string. For example +The +<link linkend="package.database.db-table.intro-database.select.buildSQL"> +<function>buildSQL</function></link> method accepts such a query array as +a parameter and returns the corresponding SQL command string. For example <programlisting role="php"> <![CDATA[<?php echo $db->buildSQL($oak); @@ -1098,8 +1113,8 @@ Column names that appear in only one table often do not need to be qualified by table names, as they are in the above example. </para><para> -As in DB_Table, such query arrays can be stored in the public -$sql property array: +As in <classname>DB_Table</classname>, such query arrays can be stored +in the public $sql property array: <programlisting role="php"> <![CDATA[<?php $db->sql['oak'] = $oak @@ -1135,13 +1150,19 @@ The select method returns a result set as a numerically indexed array of rows. Each row can represented as be either an associative or numerical array, depending on the value of the $fetch_mode -property of the <classname>DB_Table_Database</classname> object or (if this is null) the +property of the <classname>DB_Table_Database</classname> object or +(if this is null) the fetchmode of the underlying DB or MDB2 object. The class also contains selectCount and selectResult methods with behaviors and -interfaces similar to those of corresponding methods of DB_Table. -</para> <para> -The interface is the same for all three select* methods -(i.e., select, selectCount, and selectResult), and is: +interfaces similar to those of corresponding methods of +<classname>DB_Table</classname>. +</para> + +<para> +The interface is the same for all three select* methods, +<function>select</function>, +<function>selectCount</function>, and +<function>selectResult</function>. The common interface is: <programlisting role="php"> <![CDATA[ array select*( string|array $sql_key, [string $filter], [string $order], @@ -1167,11 +1188,12 @@ <refsect2 id="package.database.db-table.intro-database.select.autoJoin"> <title><function>autoJoin</function></title> <para> -autoJoin - accepts an array paramater containing the names of -desired columns and/or an array of tables names, and returns a -query array containing a WHERE clause with automatically +<function>autoJoin</function> - accepts an array paramater containing +the names of desired columns and/or an array of tables names, and returns +a query array containing a WHERE clause with automatically generated join conditions. -</para><para> +</para> +<para> Synopsis: <programlisting role="php"> <![CDATA[ @@ -1189,11 +1211,12 @@ listed in the $tables parameter, all of the tables containing the columns listed in the $cols parameter, and any linking tables required to join these tables. -</para><para> +</para> +<para> The following example generates and submits query that selects a result set in which each row contains a person's name, home phone number and -address, based on knowledge of the names of the desired columns. In -our example database, this requires that all four tables be joined. +address, based on knowledge of the names of the desired columns. In our +example database, this requires that all four tables be joined. <programlisting role="php"> <![CDATA[ <?php @@ -1210,7 +1233,8 @@ <function>validCol</function></link> method to validate and disambiguate all qualified and unqualified column names. -</para><para> +</para> +<para> The SQL command corresponding to such a query array may be obtained using <link linkend="package.database.db-table.intro-database.select.buildSQL"> @@ -1263,31 +1287,29 @@ <para> Algorithm: -The algorithm used by autoJoin is designed to find appropriate -join conditions if these exist and are unambiguous, and to -return a PEAR Error if the structure of references and linking -tables either yields a multiply connected network of joins, or -if it cannot construct an appropriate set of join conditions. -The method first examines the $col and $table property to -identify the list of tables that must be joined. It then -creates a network of joined tables (the joined set) by starting -with one table and sequentially adding tables to the joined set -from the set of tables have not yet been joined (the unjoined -set). The process starts by taking the first required table as -a nucleus of the joined set, and then iterating through the -unjoined set in search of a table that can be joined to the -first. During this and each subsequent stage of addition, the -method iterates through the unjoined set in search of a table -that can be joined to any table in the joined set (i.e., that -either references or is referenced by one of the tables in -the joined set.) If it finds an unjoined table that can be -joined to exactly one table in the joined set, that table is -added to the joined set, and the search for another table to -join begins. If the search encounters a table in the unjoined -set that can be joined to two or more tables in the joined set, -the method returns an error indicating that the join conditions -are ambiguous -- the method will only return a set of joins -that correspond to a tree graph (where tables are nodes and +The algorithm used by <function>autoJoin</function> is designed to +find appropriate join conditions if these exist and are unambiguous, +and to return a PEAR Error if the structure of references and linking +tables either yields a multiply connected network of joins, or if it +cannot construct an appropriate set of join conditions. The method +first examines the $col and $table property to identify the list of +tables that must be joined. It then creates a network of joined tables +(the joined set) by starting with one table and sequentially adding +tables to the joined set from the set of tables have not yet been +joined (the unjoined set). The process starts by taking the first +required table as a nucleus of the joined set, and then iterating +through the unjoined set in search of a table that can be joined to +the first. During this and each subsequent stage of addition, the +method iterates through the unjoined set in search of a table that +can be joined to any table in the joined set (i.e., that either +references or is referenced by one of the tables in the joined set.) +If it finds an unjoined table that can be joined to exactly one table +in the joined set, that table is added to the joined set, and the +search for another table to join begins. If the search encounters +a table in the unjoined set that can be joined to two or more tables +in the joined set, the method returns an error indicating that the +join conditions are ambiguous -- the method will only return a set +of joins that correspond to a tree graph (where tables are nodes and joins are bonds) and will reject any multiply connected set of joins. If it is found that none of the tables in the unjoined set can be directly joined to any table in the joined set, the @@ -1318,15 +1340,16 @@ string quote(mixed $value) ]]> </programlisting> -The <function>DB_Table_Database::quote</function> method calls either the DB quoteSmart or -MDB2 quote method internally. The return value is always a string, with -a return value whose format depends upon the PHP type of $value: If $value -is a string, the method returns a string that is properly quoted and -escaped for the underlying RDBMS. If $value is an integer or float, it -returns an unquoted string representation of the number. If $value is -boolean, it returns '1' for true, or '0' for false (consistent with the -representation of booleans as integers used by the <classname>DB_Table</classname> abstract data -type). If $value is null, it returns the unquoted string NULL. +The <function>DB_Table_Database::quote</function> method calls either the +<function>DB::quoteSmart</function> or <function>MDB2::quote</function> +method internally. The return value is always a string, with a return +value whose format depends upon the PHP type of $value: If $value is a +string, the method returns a string that is properly quoted and escaped +for the underlying RDBMS. If $value is an integer or float, it returns an +unquoted string representation of the number. If $value is boolean, it +returns '1' for true, or '0' for false (consistent with the representation +of booleans as integers used by the <classname>DB_Table</classname> abstract +data type). If $value is null, it returns the unquoted string NULL. </para> </refsect3> <refsect3 id="package.database.db-table.intro-database.select.buildFilter"> @@ -1369,9 +1392,9 @@ <refsect3 id="package.database.db-table.intro-database.select.buildSQL"> <title><function>buildSQL</function></title> <para> -buildSQL 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. +<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. </para> <para> Synopsis: The interface is the same as that of the select* methods: @@ -1391,7 +1414,8 @@ <refsect3 id="package.database.db-table.intro-database.select.validCol"> <title><function>validCol</function></title> <para> -validCol - validates and (if necessary) disambiguates column names. +<function>validCol</function> - validates and (if necessary) disambiguates +column names. </para> <para> Synopsis: @@ -1437,16 +1461,18 @@ <refsect1 id="package.database.db-table.intro-database.modify"> <title>Data Modification (Insert, Update, and Delete)</title> <para> -The insert, delete, and update methods of <classname>DB_Table_Database</classname> have -interfaces and behaviors similiar to those of the corresponding -methods of DB_Table. The only differences in the interfaces are -that each of these <classname>DB_Table_Database</classname> method requires an additional -first parameter whose value is the name of the table to which the -insert, update, or delete operation should be applied. The -only differences in function are that each of these three -<classname>DB_Table_Database</classname> methods can be set to silently take actions to -guarantee referential integrity. -</para><para> +The +<function>insert</function>, <function>delete</function>, and +<function>update</function> methods of <classname>DB_Table_Database</classname> +have interfaces and behaviors similiar to those of the corresponding methods +of DB_Table. The only differences in the interfaces are that each of these +<classname>DB_Table_Database</classname> method requires an additional first +parameter whose value is the name of the table to which the SQL insert, +update, or delete command should be applied. The only differences in behavior +are that each of these three <classname>DB_Table_Database</classname> methods +can be set to silently take actions to guarantee referential integrity. +</para> +<para> Synopses: <programlisting role="php"> <![CDATA[ @@ -1526,20 +1552,22 @@ each child <classname>DB_Table</classname> object is unserialized in turn by the <function>DB_Table_Database::__wakeup</function> -method. If the <classname>DB_Table</classname> objects are instances of subclasses of -DB_Table, this requires that the definitions of these subclasses -exist in memory prior to unserialization of the table. This can be -accomplished by explicitly including the file or files containing -the required class definitions in the file containing the -unserialize command, or by taking advantage of an auto-load mechanism -that is built into the wake-up method. -</para><para> +method. If the <classname>DB_Table</classname> objects are instances +of subclasses of <classname>DB_Table</classname>, this requires that +the definitions of these subclasses exist in memory prior to +unserialization of the table. This can be accomplished by explicitly +including the file or files containing the required class definitions +in the file containing the unserialize command, or by taking advantage +of an auto-load mechanism that is built into the wake-up method. +</para> +<para> In order for autoloading of subclass definitions to work, each of the subclasses must be defined in a separate file in a default directory, with a filename that is given by the class name with an added '.php' -extension. If the definition of a required subclass of <classname>DB_Table</classname> named -"classname" is found to not exist in memory when needed during -unserialization, the <function>__wakeup</function> method tries to +extension. If the definition of a required subclass of +<classname>DB_Table</classname> named "classname" is found to not exist +in memory when needed during unserialization, the +<function>__wakeup</function> method tries to include a file named "classname.php" in this directory. </para><para> For autoloading to work, the base of each such filename must be the @@ -1550,8 +1578,8 @@ <refsect2 id="package.database.db-table.intro-database.serialize.setTableSubclassPath"> <title><function>setTableSubclassPath</function></title> <para> -setTableSubclassPath - sets the path to the default directory for -DB_Table subclass definitions. +<function>setTableSubclassPath</function> - sets the path to the default +directory for <classname>DB_Table</classname> subclass definitions. </para> <para> Synopsis: <programlisting role="php"> @@ -1588,12 +1616,12 @@ $xml_string = $db->toXML(); ?>]]> </programlisting> -The DB_Table_Database::fromXML method is a static method that takes an -MDB2 XML database schema string as its only parameter and returns a -<classname>DB_Table_Database</classname> -object containing all the tables and references in the database. The -following pair of commands is necessary to create a DB_Table_Database -object and connect it to a RDBMS +The <function>DB_Table_Database::fromXML</function> method is a static method +that takes an MDB2 XML database schema string as its only parameter and returns +a <classname>DB_Table_Database</classname> object containing all the tables +and references in the database. The following pair of commands is necessary +to create a <classname>DB_Table_Database</classname> object and connect it to +a RDBMS <programlisting role="php"> <![CDATA[<?php $db = DB_Table_Database::fromXML($xml_string); @@ -1606,11 +1634,12 @@ The tables of the <classname>DB_Table_Database</classname> object that is returned by <function>fromXML</function> are all instances of <classname>DB_Table</classname> itself, rather than of custom subclasses -of DB_Table. <function>fromXML</function> returns a PEAR error if the -XML string cannot be parsed, if an error is thrown during instantiation -of either the <classname>DB_Table_Database</classname> object or any of -the child <classname>DB_Table</classname> objects, or if called with a -PHP 4 interpreter (it requires PHP 5). +of <classname>DB_Table</classname>. <function>fromXML</function> returns +a PEAR_Error if the XML string cannot be parsed, if an +error is thrown during instantiation of either the +<classname>DB_Table_Database</classname> object or any of the child +<classname>DB_Table</classname> objects, or if called with a PHP 4 +interpreter (it requires PHP 5). </para> </refsect1> @@ -1631,12 +1660,14 @@ ]]> </programlisting> Each has a boolean argument that turns on (true) or off (false) one -of the features of DB_Table. All of the relevant features affect -data insertion and updating, and are implemented within the DB_Table -insert and update methods. The <classname>DB_Table_Database</classname> -insert and update methods call the <classname>DB_Table</classname> +of the features of <classname>DB_Table</classname>. All of the relevant +features affect data insertion and updating, and are implemented within +the <classname>DB_Table</classname> +<function>insert</function> and <function>update</function> methods. +The <classname>DB_Table_Database</classname> <function>insert</function> +and <function>update</function> methods call the <classname>DB_Table</classname> insert and update methods, so changes in these properties also change -the behavior of the DB_Table_Database methods. +the behavior of the <classname>DB_Table_Database</classname> methods. </para> <para> The autoValidInsert and autoValidUpdate methods turn on or off the
http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/db-table/intro-database.xml?r1=1.1&r2=1.2&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.1 peardoc/en/package/database/db-table/intro-database.xml:1.2 --- peardoc/en/package/database/db-table/intro-database.xml:1.1 Tue May 29 18:42:23 2007 +++ peardoc/en/package/database/db-table/intro-database.xml Fri Jun 8 02:26:45 2007 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.database.db-table.intro-database"> <refnamediv> @@ -376,14 +376,14 @@ Address table (defined below). </para><para> Note the assignment of a value for the $auto_inc_col property, which -is a recent addition to DB_Table: The value of $auto_inc_col is the -name of a column that is declared to be 'auto increment'. Auto -incrementing of this column is now implemented in the insert method +is a recent addition to <classname>DB_Table</classname>: The value of +$auto_inc_col is the name of a column that is declared to be 'auto increment'. +Auto incrementing of this column is now implemented in the insert method of <classname>DB_Table</classname> using DB or MDB2 sequences. </para><para> The following code uses the same method to create subclasses of -DB_Table associated with the remaining Phone, Address, and PersonPhone -tables of database TestDB: +<classname>DB_Table</classname> associated with the remaining Phone, +Address, and PersonPhone tables of database TestDB: <programlisting role="php"> <![CDATA[<?php class Address_Table extends DB_Table @@ -442,8 +442,8 @@ 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: +The following code instantiates one object of each <classname>DB_Table</classname> +subclass, which is associated with the corresponding table: <programlisting role="php"> <![CDATA[<?php $Person = new Person_Table($conn, 'Person', 'safe'); @@ -453,35 +453,37 @@ ?>]]> </programlisting> Here, because we have used the value 'safe' for the optional third -parameter of the <classname>DB_Table</classname> constructor in each statement, each table -will be created in the RDBMS only if and only if a table of that -name does not already exist in the database. +parameter of the <classname>DB_Table</classname> constructor in each +statement, each table will be created in the RDBMS only if and only +if a table of that name does not already exist in the database. </para> <para> It is recommended that constructor statements be placed in a separate -file from any of the <classname>DB_Table</classname> subclass definitions. Doing so makes it -easier to +file from any of the <classname>DB_Table</classname> subclass definitions. +Doing so makes it easier to <link linkend="package.database.db-table.intro-database.serialize"> serialize and unserialize</link> the -DB_Table and <classname>DB_Table_Database</classname> objects, because a php file in which -an instance of a <classname>DB_Table</classname> subclass is unserialized must have access -to the subclass definition, but should not include the constructor -statements. Putting each <classname>DB_Table</classname> subclass definition in a separate -file, with a name that is the same as the subclass name, also allows -the subclass definitions to be autoloaded when an object is -serialized, as discussed +<classname>DB_Table</classname> and <classname>DB_Table_Database</classname> +objects, because a php file in which an instance of a +<classname>DB_Table</classname> subclass is unserialized must have access +to the subclass definition, but should not include the constructor statements. +Putting each <classname>DB_Table</classname> subclass definition in a separate +file, with a name that is the subclass name with a .php extension, also allows +the subclass definitions to be autoloaded when an object is serialized, as +discussed <link linkend="package.database.db-table.intro-database.serialize">below</link>. </para> <para> -An alternative way to create a <classname>DB_Table</classname> object is to create an -instance of <classname>DB_Table</classname> itself, rather than of a subclass of DB_Table. -In this method, one first instantiates a generic <classname>DB_Table</classname> object, -which initially contains no information about the table schema, and -then sets the values of the public $col and $idx properties needed -to define a table schema. As an example, the following code constructs -the Person table as an instance of DB_Table: +An alternative way to create a <classname>DB_Table</classname> object is to +create an instance of <classname>DB_Table</classname> itself, rather than +of a subclass of <classname>DB_Table</classname>. In this method, one first +instantiates a generic <classname>DB_Table</classname> object, which initially +contains no information about the table schema, and then sets the values of +the public $col and $idx properties needed to define a table schema. As an +example, the following code constructs an instance of DB_Table that represents +the Person table: <programlisting role="php"> <![CDATA[<?php $Person = new DB_Table($conn, 'Person'); @@ -500,16 +502,19 @@ ?> ]]> </programlisting> -This method is valid only in recent versions of the <classname>DB_Table</classname> package -(1.5.0RC1 and greater) that contain the <classname>DB_Table_Database</classname> class. Earlier -versions of <classname>DB_Table</classname> required that <classname>DB_Table</classname> always be extended. The -only real disadvantage of using such generic <classname>DB_Table</classname> objects is that -it makes it impossible to override the methods of <classname>DB_Table</classname> to, for -example, customize the insert or update method so as to implement -business rules for a table. Generic <classname>DB_Table</classname> objects are used by the -fromXML method, which takes an XML description of a database schema -as a parameter, and returns a <classname>DB_Table_Database</classname> object in which each -of the child tables is represented by an instance of DB_Table. +This method is valid only in recent versions of the +<classname>DB_Table</classname> package (1.5.0RC1 and greater) that contain +the <classname>DB_Table_Database</classname> class. Earlier versions of +<classname>DB_Table</classname> required that <classname>DB_Table</classname> +always be extended. The only real disadvantage of using such generic +<classname>DB_Table</classname> objects is that it makes it impossible to +override the methods of <classname>DB_Table</classname> to, for example, +customize the insert or update method so as to implement business rules +for a table. Generic <classname>DB_Table</classname> objects are used by +the <function>fromXML</function> method, which takes an XML description of +a database schema as a parameter, and returns a +<classname>DB_Table_Database</classname> object in which each of the child +tables is represented by an instance of <classname>DB_Table</classname>. </para> </refsect1> @@ -544,27 +549,28 @@ <title>Building a Model</title> <para> To construct a model of a relational database, after instantiating a -set of <classname>DB_Table</classname> objects and a <classname>DB_Table_Database</classname> object, we must add -the table objects to the database object, add declarations of foreign -key references, and declare many-to-many relationships that involve -linking tables, in that order. +set of <classname>DB_Table</classname> objects and a +<classname>DB_Table_Database</classname> object, we must add the table +objects to the database object, add declarations of foreign key +references, and declare many-to-many relationships that involve linking +tables, in that order. </para> <refsect2 id="package.database.db-table.intro-database.model.addTable"> <title>Adding Tables</title> <para> -After a <classname>DB_Table</classname> object is instantiated, it can be added to the parent -database with the <function>DB_Table_Database::addTable</function> -method. The interface +After a <classname>DB_Table</classname> object is instantiated, it +can be added to the parent database with the +<function>DB_Table_Database::addTable</function> method. The interface for this method is <programlisting role="php"> <![CDATA[ true|Error addTable(object &$Table) ]]> </programlisting> -where $Table is a <classname>DB_Table</classname> object that is passed by reference. The -method returns boolean true on normal completion, and a PEAR Error -object on failure. +where $Table is a <classname>DB_Table</classname> object that is passed +by reference. The method returns boolean true on normal completion, and +a PEAR_Error object on failure. </para><para> The following code adds the four tables of our example database to the $db <classname>DB_Table_Database</classname> object: @@ -592,20 +598,21 @@ </para><para> Synopsis (simplified): <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ true|Error addRef(string $ftable, string|array $fkey, string $rtable, [string|array] $rkey] ) -?>]]> +]]> </programlisting> Here $ftable is the name of a referencing (or foreign key) table, $fkey is the foreign key, $rtable is the name of the referenced table, and $rkey is the (optional) referenced key. If the optional $rkey parameter is absent or null, the referenced key is taken by default to be the primary key of the referenced table. The foreign and referenced key values are specified -using the same syntax as that used to define indices in DB_Table: Each key +using the same syntax as that used to define indices in +<classname>DB_Table</classname>: Each key may be either a column name string, for a single-column key, or a sequential array of column names, for a multi-column key. The method returns true on -normal completion, and a PEAR Error on failure. The simplified synopsis +normal completion, and a PEAR_Error on failure. The 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 @@ -613,9 +620,11 @@ For example, the command: <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ +<?php $db->addRef('Person', 'AddressID', 'Address', 'AddressID'); -?>]]> +?> +]]> </programlisting> adds a reference from foreign key Person.AddressID of referencing table Person to the primary key Address.AddressID of referenced table Address. @@ -631,8 +640,8 @@ is defined, as required by standard SQL. </para><para> A reference between two tables can only be added after both the referencing -and referenced <classname>DB_Table</classname> objects have been instantiated and added to the -parent DB_Table_Datbase instance. +and referenced <classname>DB_Table</classname> objects have been instantiated +and added to the parent <classname>DB_Table_Datbase</classname> instance. </para> </refsect2> @@ -652,9 +661,9 @@ </para><para> Synopsis: <programlisting role="php"> -<![CDATA[<?php +<![CDATA[ true|Error addLink(string $table1, string $table2, string $link) -?>]]> +]]> </programlisting> Here, $link is the name of a linking table that links tables named $table1 and $table2. All three parameters are required, and all must @@ -808,7 +817,7 @@ </para> <para id="package.database.db-table.intro-database.model.delete.table"> -deleteTable - deletes a table from the database model +<function>deleteTable</function> - deletes a table from the database model </para> <para> @@ -860,12 +869,12 @@ <refsect1 id="package.database.db-table.intro-database.refAction"> <title>On Delete and On Update Actions</title> <para> -<classname>DB_Table_Database</classname> optionally provides actions designed to enforce -referential integrity that are provided by ANSI SQL, but that are +<classname>DB_Table_Database</classname> optionally provides actions designed +to enforce referential integrity that are provided by ANSI SQL, but that are not provided by some popular databases (e.g., SQLite and the default -MySQL engine). <classname>DB_Table_Database</classname> offers optional PHP emulation of -referentially triggered ON DELETE and ON UPDATE actions, such as -cascading deletes (discussed here), and also optionally checks the +MySQL engine). <classname>DB_Table_Database</classname> offers optional PHP +emulation of referentially triggered ON DELETE and ON UPDATE actions, such +as cascading deletes (discussed here), and also optionally checks the validity of foreign key values before insertion or updating (discussed <link linkend="package.database.db-table.intro-database.FKeyCheck">below</link>) @@ -983,7 +992,8 @@ for that reference, i.e., either an action strings or null. A null parameter is used to indicate that no action on delete or update of rows of table $rtable. -</para><para> +</para> +<para> For example, the following code would change the 'on_update' action associated with the the reference from 'PersonPhone' to 'Person' to a 'restrict' action: @@ -1020,21 +1030,22 @@ default, PHP emulation of both ON DELETE and ON UPDATE actions is on. Calling either of these methods with a false value does not modify the values of the instance property (the $_ref property) that records -the on delete or on update actions associated with each reference: It -merely prevents PHP emulation of these actions by the DB_Table_Database -<function>delete</function> and -<function>update</function> methods. +the on delete or on update actions associated with each reference: +It merely prevents PHP emulation of these actions by the +<function>DB_Table_Database::delete</function> and +<function>DB_Table_Database::update</function> methods. </para> </refsect2> </refsect1> <refsect1 id="package.database.db-table.intro-database.FKeyCheck"> -<title>Foreign Key Validity Checks</title> +<title>Foreign Key Validation</title> <para> -By default, <classname>DB_Table_Database</classname> checks the validity of foreign key values -before inserting or updating data in a table with foreign keys. That is, -before inserting a row, or updating any foreign key column values, the -insert and update methods of <classname>DB_Table_Database</classname> actually submit a query +By default, <classname>DB_Table_Database</classname> checks the validity +of foreign key values before inserting or updating data in a table with +foreign keys. That is, before inserting a row, or updating any foreign key +column values, the <function>insert</function> and <function>update</function> +methods of <classname>DB_Table_Database</classname> actually submit a query to confirm that the inserted or updated foreign key column values correspond to values of the referenced columns of an existing row in the referenced table. By default, both methods throw an error, and do not modify the data, @@ -1043,7 +1054,7 @@ <para id="package.database.db-table.intro-database.FKeyCheck.setCheckFKey"> This checking of foreign key validity by the PHP layer may be turned on or off, for insertion or updating of any table in database, with the -FKeyCheck.setCheckFKey method. The interface of this method is: +<function>setCheckFKey</function> method. The interface of this method is: <programlisting role="php"> <![CDATA[void setCheckFKey(bool $flag);]]> </programlisting> @@ -1055,17 +1066,19 @@ <refsect1 id="package.database.db-table.intro-database.select"> <title>Data Selection</title> <para> -<classname>DB_Table_Database</classname> provides an object-oriented interface for SQL -select statements that is almost identical to that of DB_Table. +<classname>DB_Table_Database</classname> provides an object-oriented +interface for SQL select statements that is almost identical to that of +<classname>DB_Table</classname>. </para> <refsect2 id="package.database.db-table.intro-database.select.query"> <title>Query Arrays</title> <para> -As in DB_Table, queries are represented in <classname>DB_Table_Database</classname> as arrays -in which each array element represents one clause of a corresponding -SQL select statement. For example, a query for names of all people that -live on Oak Street in Anytown in our example database might be +As in <classname>DB_Table</classname>, queries are represented in +<classname>DB_Table_Database</classname> as arrays, in which array +elements represents clauses of a corresponding SQL select statement. +For example, a query for names of all people that live on Oak Street +in Anytown in our example database might be <programlisting role="php"> <![CDATA[<?php $oak = array( @@ -1077,8 +1090,10 @@ 'order' => 'Address.Building' ); ?>]]> </programlisting> -The <link linkend="package.database.db-table.intro-database.select.buildSQL">buildSQL</link> method accepts such a query array -as a parameter and returns the corresponding SQL command string. For example +The +<link linkend="package.database.db-table.intro-database.select.buildSQL"> +<function>buildSQL</function></link> method accepts such a query array as +a parameter and returns the corresponding SQL command string. For example <programlisting role="php"> <![CDATA[<?php echo $db->buildSQL($oak); @@ -1098,8 +1113,8 @@ Column names that appear in only one table often do not need to be qualified by table names, as they are in the above example. </para><para> -As in DB_Table, such query arrays can be stored in the public -$sql property array: +As in <classname>DB_Table</classname>, such query arrays can be stored +in the public $sql property array: <programlisting role="php"> <![CDATA[<?php $db->sql['oak'] = $oak @@ -1135,13 +1150,19 @@ The select method returns a result set as a numerically indexed array of rows. Each row can represented as be either an associative or numerical array, depending on the value of the $fetch_mode -property of the <classname>DB_Table_Database</classname> object or (if this is null) the +property of the <classname>DB_Table_Database</classname> object or +(if this is null) the fetchmode of the underlying DB or MDB2 object. The class also contains selectCount and selectResult methods with behaviors and -interfaces similar to those of corresponding methods of DB_Table. -</para> <para> -The interface is the same for all three select* methods -(i.e., select, selectCount, and selectResult), and is: +interfaces similar to those of corresponding methods of +<classname>DB_Table</classname>. +</para> + +<para> +The interface is the same for all three select* methods, +<function>select</function>, +<function>selectCount</function>, and +<function>selectResult</function>. The common interface is: <programlisting role="php"> <![CDATA[ array select*( string|array $sql_key, [string $filter], [string $order], @@ -1167,11 +1188,12 @@ <refsect2 id="package.database.db-table.intro-database.select.autoJoin"> <title><function>autoJoin</function></title> <para> -autoJoin - accepts an array paramater containing the names of -desired columns and/or an array of tables names, and returns a -query array containing a WHERE clause with automatically +<function>autoJoin</function> - accepts an array paramater containing +the names of desired columns and/or an array of tables names, and returns +a query array containing a WHERE clause with automatically generated join conditions. -</para><para> +</para> +<para> Synopsis: <programlisting role="php"> <![CDATA[ @@ -1189,11 +1211,12 @@ listed in the $tables parameter, all of the tables containing the columns listed in the $cols parameter, and any linking tables required to join these tables. -</para><para> +</para> +<para> The following example generates and submits query that selects a result set in which each row contains a person's name, home phone number and -address, based on knowledge of the names of the desired columns. In -our example database, this requires that all four tables be joined. +address, based on knowledge of the names of the desired columns. In our +example database, this requires that all four tables be joined. <programlisting role="php"> <![CDATA[ <?php @@ -1210,7 +1233,8 @@ <function>validCol</function></link> method to validate and disambiguate all qualified and unqualified column names. -</para><para> +</para> +<para> The SQL command corresponding to such a query array may be obtained using <link linkend="package.database.db-table.intro-database.select.buildSQL"> @@ -1263,31 +1287,29 @@ <para> Algorithm: -The algorithm used by autoJoin is designed to find appropriate -join conditions if these exist and are unambiguous, and to -return a PEAR Error if the structure of references and linking -tables either yields a multiply connected network of joins, or -if it cannot construct an appropriate set of join conditions. -The method first examines the $col and $table property to -identify the list of tables that must be joined. It then -creates a network of joined tables (the joined set) by starting -with one table and sequentially adding tables to the joined set -from the set of tables have not yet been joined (the unjoined -set). The process starts by taking the first required table as -a nucleus of the joined set, and then iterating through the -unjoined set in search of a table that can be joined to the -first. During this and each subsequent stage of addition, the -method iterates through the unjoined set in search of a table -that can be joined to any table in the joined set (i.e., that -either references or is referenced by one of the tables in -the joined set.) If it finds an unjoined table that can be -joined to exactly one table in the joined set, that table is -added to the joined set, and the search for another table to -join begins. If the search encounters a table in the unjoined -set that can be joined to two or more tables in the joined set, -the method returns an error indicating that the join conditions -are ambiguous -- the method will only return a set of joins -that correspond to a tree graph (where tables are nodes and +The algorithm used by <function>autoJoin</function> is designed to +find appropriate join conditions if these exist and are unambiguous, +and to return a PEAR Error if the structure of references and linking +tables either yields a multiply connected network of joins, or if it +cannot construct an appropriate set of join conditions. The method +first examines the $col and $table property to identify the list of +tables that must be joined. It then creates a network of joined tables +(the joined set) by starting with one table and sequentially adding +tables to the joined set from the set of tables have not yet been +joined (the unjoined set). The process starts by taking the first +required table as a nucleus of the joined set, and then iterating +through the unjoined set in search of a table that can be joined to +the first. During this and each subsequent stage of addition, the +method iterates through the unjoined set in search of a table that +can be joined to any table in the joined set (i.e., that either +references or is referenced by one of the tables in the joined set.) +If it finds an unjoined table that can be joined to exactly one table +in the joined set, that table is added to the joined set, and the +search for another table to join begins. If the search encounters +a table in the unjoined set that can be joined to two or more tables +in the joined set, the method returns an error indicating that the +join conditions are ambiguous -- the method will only return a set +of joins that correspond to a tree graph (where tables are nodes and joins are bonds) and will reject any multiply connected set of joins. If it is found that none of the tables in the unjoined set can be directly joined to any table in the joined set, the @@ -1318,15 +1340,16 @@ string quote(mixed $value) ]]> </programlisting> -The <function>DB_Table_Database::quote</function> method calls either the DB quoteSmart or -MDB2 quote method internally. The return value is always a string, with -a return value whose format depends upon the PHP type of $value: If $value -is a string, the method returns a string that is properly quoted and -escaped for the underlying RDBMS. If $value is an integer or float, it -returns an unquoted string representation of the number. If $value is -boolean, it returns '1' for true, or '0' for false (consistent with the -representation of booleans as integers used by the <classname>DB_Table</classname> abstract data -type). If $value is null, it returns the unquoted string NULL. +The <function>DB_Table_Database::quote</function> method calls either the +<function>DB::quoteSmart</function> or <function>MDB2::quote</function> +method internally. The return value is always a string, with a return +value whose format depends upon the PHP type of $value: If $value is a +string, the method returns a string that is properly quoted and escaped +for the underlying RDBMS. If $value is an integer or float, it returns an +unquoted string representation of the number. If $value is boolean, it +returns '1' for true, or '0' for false (consistent with the representation +of booleans as integers used by the <classname>DB_Table</classname> abstract +data type). If $value is null, it returns the unquoted string NULL. </para> </refsect3> <refsect3 id="package.database.db-table.intro-database.select.buildFilter"> @@ -1369,9 +1392,9 @@ <refsect3 id="package.database.db-table.intro-database.select.buildSQL"> <title><function>buildSQL</function></title> <para> -buildSQL 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. +<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. </para> <para> Synopsis: The interface is the same as that of the select* methods: @@ -1391,7 +1414,8 @@ <refsect3 id="package.database.db-table.intro-database.select.validCol"> <title><function>validCol</function></title> <para> -validCol - validates and (if necessary) disambiguates column names. +<function>validCol</function> - validates and (if necessary) disambiguates +column names. </para> <para> Synopsis: @@ -1437,16 +1461,18 @@ <refsect1 id="package.database.db-table.intro-database.modify"> <title>Data Modification (Insert, Update, and Delete)</title> <para> -The insert, delete, and update methods of <classname>DB_Table_Database</classname> have -interfaces and behaviors similiar to those of the corresponding -methods of DB_Table. The only differences in the interfaces are -that each of these <classname>DB_Table_Database</classname> method requires an additional -first parameter whose value is the name of the table to which the -insert, update, or delete operation should be applied. The -only differences in function are that each of these three -<classname>DB_Table_Database</classname> methods can be set to silently take actions to -guarantee referential integrity. -</para><para> +The +<function>insert</function>, <function>delete</function>, and +<function>update</function> methods of <classname>DB_Table_Database</classname> +have interfaces and behaviors similiar to those of the corresponding methods +of DB_Table. The only differences in the interfaces are that each of these +<classname>DB_Table_Database</classname> method requires an additional first +parameter whose value is the name of the table to which the SQL insert, +update, or delete command should be applied. The only differences in behavior +are that each of these three <classname>DB_Table_Database</classname> methods +can be set to silently take actions to guarantee referential integrity. +</para> +<para> Synopses: <programlisting role="php"> <![CDATA[ @@ -1526,20 +1552,22 @@ each child <classname>DB_Table</classname> object is unserialized in turn by the <function>DB_Table_Database::__wakeup</function> -method. If the <classname>DB_Table</classname> objects are instances of subclasses of -DB_Table, this requires that the definitions of these subclasses -exist in memory prior to unserialization of the table. This can be -accomplished by explicitly including the file or files containing -the required class definitions in the file containing the -unserialize command, or by taking advantage of an auto-load mechanism -that is built into the wake-up method. -</para><para> +method. If the <classname>DB_Table</classname> objects are instances +of subclasses of <classname>DB_Table</classname>, this requires that +the definitions of these subclasses exist in memory prior to +unserialization of the table. This can be accomplished by explicitly +including the file or files containing the required class definitions +in the file containing the unserialize command, or by taking advantage +of an auto-load mechanism that is built into the wake-up method. +</para> +<para> In order for autoloading of subclass definitions to work, each of the subclasses must be defined in a separate file in a default directory, with a filename that is given by the class name with an added '.php' -extension. If the definition of a required subclass of <classname>DB_Table</classname> named -"classname" is found to not exist in memory when needed during -unserialization, the <function>__wakeup</function> method tries to +extension. If the definition of a required subclass of +<classname>DB_Table</classname> named "classname" is found to not exist +in memory when needed during unserialization, the +<function>__wakeup</function> method tries to include a file named "classname.php" in this directory. </para><para> For autoloading to work, the base of each such filename must be the @@ -1550,8 +1578,8 @@ <refsect2 id="package.database.db-table.intro-database.serialize.setTableSubclassPath"> <title><function>setTableSubclassPath</function></title> <para> -setTableSubclassPath - sets the path to the default directory for -DB_Table subclass definitions. +<function>setTableSubclassPath</function> - sets the path to the default +directory for <classname>DB_Table</classname> subclass definitions. </para> <para> Synopsis: <programlisting role="php"> @@ -1588,12 +1616,12 @@ $xml_string = $db->toXML(); ?>]]> </programlisting> -The DB_Table_Database::fromXML method is a static method that takes an -MDB2 XML database schema string as its only parameter and returns a -<classname>DB_Table_Database</classname> -object containing all the tables and references in the database. The -following pair of commands is necessary to create a DB_Table_Database -object and connect it to a RDBMS +The <function>DB_Table_Database::fromXML</function> method is a static method +that takes an MDB2 XML database schema string as its only parameter and returns +a <classname>DB_Table_Database</classname> object containing all the tables +and references in the database. The following pair of commands is necessary +to create a <classname>DB_Table_Database</classname> object and connect it to +a RDBMS <programlisting role="php"> <![CDATA[<?php $db = DB_Table_Database::fromXML($xml_string); @@ -1606,11 +1634,12 @@ The tables of the <classname>DB_Table_Database</classname> object that is returned by <function>fromXML</function> are all instances of <classname>DB_Table</classname> itself, rather than of custom subclasses -of DB_Table. <function>fromXML</function> returns a PEAR error if the -XML string cannot be parsed, if an error is thrown during instantiation -of either the <classname>DB_Table_Database</classname> object or any of -the child <classname>DB_Table</classname> objects, or if called with a -PHP 4 interpreter (it requires PHP 5). +of <classname>DB_Table</classname>. <function>fromXML</function> returns +a PEAR_Error if the XML string cannot be parsed, if an +error is thrown during instantiation of either the +<classname>DB_Table_Database</classname> object or any of the child +<classname>DB_Table</classname> objects, or if called with a PHP 4 +interpreter (it requires PHP 5). </para> </refsect1> @@ -1631,12 +1660,14 @@ ]]> </programlisting> Each has a boolean argument that turns on (true) or off (false) one -of the features of DB_Table. All of the relevant features affect -data insertion and updating, and are implemented within the DB_Table -insert and update methods. The <classname>DB_Table_Database</classname> -insert and update methods call the <classname>DB_Table</classname> +of the features of <classname>DB_Table</classname>. All of the relevant +features affect data insertion and updating, and are implemented within +the <classname>DB_Table</classname> +<function>insert</function> and <function>update</function> methods. +The <classname>DB_Table_Database</classname> <function>insert</function> +and <function>update</function> methods call the <classname>DB_Table</classname> insert and update methods, so changes in these properties also change -the behavior of the DB_Table_Database methods. +the behavior of the <classname>DB_Table_Database</classname> methods. </para> <para> The autoValidInsert and autoValidUpdate methods turn on or off the