cvs: peardoc /en/package/database/db-dataobject intro-autobuilding.xml intro-configuration.xml intro-filters.xml
| From: | Alan Knowles | Date: | Tue, 11 Nov 2003 13:50:49 +0000 |
| Subject: | cvs: peardoc /en/package/database/db-dataobject intro-autobuilding.xml intro-configuration.xml intro-filters.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-1942@lists.php.net to get a copy of this message | ||
alan_k Tue Nov 11 08:50:49 2003 EDT
Modified files:
/peardoc/en/package/database/db-dataobject intro-autobuilding.xml
intro-configuration.xml
intro-filters.xml
Log:
improve documentation
Index: peardoc/en/package/database/db-dataobject/intro-autobuilding.xml diff -u peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.6 peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.7 --- peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.6 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-autobuilding.xml Tue Nov 11 08:50:49 2003 @@ -1,59 +1,59 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.database.db-dataobject.intro-autobuilding"> - <refnamediv> - <refname>Auto Building</refname> - <refpurpose> - creating the base Classes and Database schema - </refpurpose> - </refnamediv> - <refsect1> - <title>What the Auto Builder (<command>createTables.php</command>) does</title> - <para> - One of the essential features of an SQL building tool is to to have some understanding of the - database structure, So that Integers can be checked, and strings can be escaped. There a few ways - that Querying the database for the table structure could be accomplished - - <itemizedlist> - <listitem> - <simpara>on every SQL query</simpara> - </listitem> - <listitem> - <simpara>At the initialization of every web page.</simpara> - </listitem> - <listitem> - <simpara>Once, while setting up the application, and store it in a file</simpara> - </listitem> - </itemizedlist> - <classname>DB_DataObject</classname> uses the last of these, it utilizes the - <ulink url="&url.php.lookup;parse-ini-file"><function>parse_ini_file</function></ulink> - function to read the file, so it should be - reasonably fast. However this does involve a stage of setting up - <classname>DB_DataObject</classname> prior to use. - </para> - <para> - The other key concept of <classname>DB_DataObject</classname> is that you work with extended - classes of <classname>DB_DataObject</classname>, which - do all the 'table' related work. Setting up these classes for a large database can be time consuming, so - the <command>createTables.php</command> file will automatically build the skeletons for all these class files. - </para> - <para> - To start the auto builder simply go to the - <parameter>pear/DB/DataObject/</parameter> directory, and type - <command>c:\php4\php.exe createTables.php myconfig.ini</command> this will read your configuration file - and generate all the base classes, along with the data definition file. - </para> - </refsect1> - <refsect1> - <title>Default Class Definition</title> - <para> - The default generated class looks like this. - <example> - <title>an generated extended class</title> - <programlisting role="php"><![CDATA[ + <refnamediv> + <refname>Auto Building and Database Schema</refname> + <refpurpose> + creating the base Classes and Database schema + </refpurpose> + </refnamediv> + <refsect1> + <title>What the Auto Builder (<command>createTables.php</command>) does</title> + <para> + One of the essential features of an SQL building tool is to to have some understanding of the + database structure, So that Integers can be checked, and strings can be escaped. There a few ways + that Querying the database for the table structure could be accomplished + + <itemizedlist> + <listitem> + <simpara>on every SQL query</simpara> + </listitem> + <listitem> + <simpara>At the initialization of every web page.</simpara> + </listitem> + <listitem> + <simpara>Once, while setting up the application, and store it in a file</simpara> + </listitem> + </itemizedlist> + <classname>DB_DataObject</classname> uses the last of these, it utilizes the + <ulink url="&url.php.lookup;parse-ini-file"><function>parse_ini_file</function></ulink> + function to read the file, so it should be + reasonably fast. However this does involve a stage of setting up + <classname>DB_DataObject</classname> prior to use. + </para> + <para> + The other key concept of <classname>DB_DataObject</classname> is that you work with extended + classes of <classname>DB_DataObject</classname>, which + do all the 'table' related work. Setting up these classes for a large database can be time consuming, so + the <command>createTables.php</command> file will automatically build the skeletons for all these class files. + </para> + <para> + To start the auto builder simply go to the + <parameter>pear/DB/DataObject/</parameter> directory, and type + <command>c:\php4\php.exe createTables.php myconfig.ini</command> this will read your configuration file + and generate all the base classes, along with the data definition file. + </para> + </refsect1> + <refsect1> + <title>Default Class Definition</title> + <para> + The default generated class looks like this. + <example> + <title>an generated extended class</title> + <programlisting role="php"><![CDATA[ @@ -92,34 +92,48 @@ ]]> - </programlisting> - </example> - </para> - <para> + </programlisting> + </example> + </para> + <para> The class defines the table name, and comments some of table columns for your reference, It also adds the <link linkend="package.database.db-dataobject.db-dataobject.staticget"> <function>staticGet</function></link> method, which can be used to quickly get single rows as Objects. You should add your table related code after the <constant>###END_AUTOCODE</constant>. - </para> - <para> + </para> + <para> The <function>__clone</function> function will only be generated on pre Zend Engine 2 applications, and it is recommended to use it so that your code will be Forward and Backward Compatible with the new engine. - </para> - </refsect1> + </para> + </refsect1> - <refsect1> - <title>Database Definition File</title> - <para> - The default generated database definition file looks like this. - <example> - <title>Database configuration file</title> - <programlisting role="ini"><![CDATA[ + <refsect1> + <title>Database Schema File</title> + <para> + The default generated database definition file looks like this, it is located in the directory set by the + "schema_location" configuration option, and is named the same as the database. + + </para><para> + If you rename the database, you will either have to regenerate the file or copy it to match the same name. + </para><para> + If you change the database schema (eg. add a column or change the type), you will have to regenerate the schema, + using createTables.php, At present, this is not done automatically (although this may be added in the future..) + </para><para> + You should not edit this file by hand (as any changes will be lost when regenerating it). You can override the + keys of a table by using a configuration option "sequence_{table} = keyquot; + + + + + <example> + <title>Database configuration file</title> + <programlisting role="ini"><![CDATA[ [group] id = 1 @@ -137,18 +151,120 @@ id = 1 ]]> - </programlisting> - </example> - </para> - <para> + </programlisting> + </example> + </para> + <para> The blocks indicate either tables and the type of field (1=integer,2=string), or a list of keys for each table. You should not need to edit file. - </para> + </para> - </refsect1> - </refentry> + </refsect1> + + <refsect1> + <title>Alternatives to using a Schema File</title> + <para> + It is possible to use DataObjects without a schema file, this can be achieved in 2 ways + + <itemizedlist> + <listitem> + <simpara>by defining the table() and keys() methods in an extended class</simpara> + </listitem> + <listitem> + <simpara>by passing an array to table() and keys() when you have an instance of dataobjects</simpara> + </listitem> + </itemizedlist> + + The second of this is demostrated on the keys() and tables() page. + </para> + <para> + Below is a hand coded class which does not use a schema.ini file. + </para> + + <para> + It was designed to be a return value from a method, rather than an object variable, so that the output of + print_r(), would not include extra information (and would be smaller when dumping a large result set. + + + <example> + <title>A Hand Coded extended class</title> + <programlisting role="php"><![CDATA[ + + + +/* +* Table Definition for group +*/ + + +class DataObjects_Grp extends DB_DataObject { + + // you can define these yourself + + var $__table='group'; // table name + var $id; // int primary_key + var $name; // string + var $grp_owner; // int + var $official; // string + var $street; // string + var $postcode; // string + var $city; // string + var $homepage; // string + var $email; // string + var $extra; // blob + + + // these are usefull to be consistant with a autogenerated file. + + /* ZE2 compatibility trick */ + function __clone() { return $this;} + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Grp',$k,$v); } + + + // now define your table structure. + // key is column name, value is type + function table() { + array( + 'id' => DB_DATAOBJECT_INT, + 'name' => DB_DATAOBJECT_STR, + 'bday' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE, + 'last' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, + 'active' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL, + 'desc' => DB_DATAOBJECT_STR + DB_DATAOBJECT_TXT, + 'photo' => DB_DATAOBJECT_STR + DB_DATAOBJECT_BLOB, + )); + } + + // now define the keys. + function keys() { + return array('id'); + } + + + +} + + +]]> + </programlisting> + </example> + </para> + <para> + + The blocks indicate either tables and the type of field (1=integer,2=string), + or a list of keys for each table. You should not need to edit file. + + </para> + + </refsect1> + + + +</refentry> <!-- Keep this comment at the end of the file Local variables: Index: peardoc/en/package/database/db-dataobject/intro-configuration.xml diff -u peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.6 peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.7 --- peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.6 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-configuration.xml Tue Nov 11 08:50:49 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.database.db-dataobject.intro-configuration"> <refnamediv> @@ -149,6 +149,43 @@ <variablelist> + <varlistentry> + <term> + <parameter>sequence_{table}</parameter> + <type>string</type> + </term> + <listitem> + <para> + To Hard code the key (autoincrement/nextval() for a table to a specific key ,overriding anything in the keys + definition of the file. Normally used on databases that are not able to be queried correctly for their structure + <example> + <title> using login as the key for the person table</title> + <programlisting role="ini"><![CDATA[ + + +sequence_person = login + + + + ]]></programlisting> + </example> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <parameter>ignore_sequence_keys</parameter> + <type>string</type> + </term> + <listitem> + <para> + If you do not want to use pear's nextval(), for automatically filling in sequences, this can disable it for + "ALL", or a list of tables "person,cart,group" + </para> + </listitem> + </varlistentry> + <varlistentry> <term> <parameter>debug</parameter> Index: peardoc/en/package/database/db-dataobject/intro-filters.xml diff -u peardoc/en/package/database/db-dataobject/intro-filters.xml:1.2 peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 --- peardoc/en/package/database/db-dataobject/intro-filters.xml:1.2 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-filters.xml Tue Nov 11 08:50:49 2003 @@ -1,8 +1,8 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.database.db-dataobject.intro-filters"> <refnamediv> - <refname>Advanced Filters</refname> + <refname>Selecting Specific data (SELECT)</refname> <refpurpose> Advanced Filters - ::query(), ::SelectAdd(), ::whereAdd(), ::Limit(), ::OrderBy(), ::GroupBy(), </refpurpose>
Index: peardoc/en/package/database/db-dataobject/intro-autobuilding.xml diff -u peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.6 peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.7 --- peardoc/en/package/database/db-dataobject/intro-autobuilding.xml:1.6 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-autobuilding.xml Tue Nov 11 08:50:49 2003 @@ -1,59 +1,59 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.database.db-dataobject.intro-autobuilding"> - <refnamediv> - <refname>Auto Building</refname> - <refpurpose> - creating the base Classes and Database schema - </refpurpose> - </refnamediv> - <refsect1> - <title>What the Auto Builder (<command>createTables.php</command>) does</title> - <para> - One of the essential features of an SQL building tool is to to have some understanding of the - database structure, So that Integers can be checked, and strings can be escaped. There a few ways - that Querying the database for the table structure could be accomplished - - <itemizedlist> - <listitem> - <simpara>on every SQL query</simpara> - </listitem> - <listitem> - <simpara>At the initialization of every web page.</simpara> - </listitem> - <listitem> - <simpara>Once, while setting up the application, and store it in a file</simpara> - </listitem> - </itemizedlist> - <classname>DB_DataObject</classname> uses the last of these, it utilizes the - <ulink url="&url.php.lookup;parse-ini-file"><function>parse_ini_file</function></ulink> - function to read the file, so it should be - reasonably fast. However this does involve a stage of setting up - <classname>DB_DataObject</classname> prior to use. - </para> - <para> - The other key concept of <classname>DB_DataObject</classname> is that you work with extended - classes of <classname>DB_DataObject</classname>, which - do all the 'table' related work. Setting up these classes for a large database can be time consuming, so - the <command>createTables.php</command> file will automatically build the skeletons for all these class files. - </para> - <para> - To start the auto builder simply go to the - <parameter>pear/DB/DataObject/</parameter> directory, and type - <command>c:\php4\php.exe createTables.php myconfig.ini</command> this will read your configuration file - and generate all the base classes, along with the data definition file. - </para> - </refsect1> - <refsect1> - <title>Default Class Definition</title> - <para> - The default generated class looks like this. - <example> - <title>an generated extended class</title> - <programlisting role="php"><![CDATA[ + <refnamediv> + <refname>Auto Building and Database Schema</refname> + <refpurpose> + creating the base Classes and Database schema + </refpurpose> + </refnamediv> + <refsect1> + <title>What the Auto Builder (<command>createTables.php</command>) does</title> + <para> + One of the essential features of an SQL building tool is to to have some understanding of the + database structure, So that Integers can be checked, and strings can be escaped. There a few ways + that Querying the database for the table structure could be accomplished + + <itemizedlist> + <listitem> + <simpara>on every SQL query</simpara> + </listitem> + <listitem> + <simpara>At the initialization of every web page.</simpara> + </listitem> + <listitem> + <simpara>Once, while setting up the application, and store it in a file</simpara> + </listitem> + </itemizedlist> + <classname>DB_DataObject</classname> uses the last of these, it utilizes the + <ulink url="&url.php.lookup;parse-ini-file"><function>parse_ini_file</function></ulink> + function to read the file, so it should be + reasonably fast. However this does involve a stage of setting up + <classname>DB_DataObject</classname> prior to use. + </para> + <para> + The other key concept of <classname>DB_DataObject</classname> is that you work with extended + classes of <classname>DB_DataObject</classname>, which + do all the 'table' related work. Setting up these classes for a large database can be time consuming, so + the <command>createTables.php</command> file will automatically build the skeletons for all these class files. + </para> + <para> + To start the auto builder simply go to the + <parameter>pear/DB/DataObject/</parameter> directory, and type + <command>c:\php4\php.exe createTables.php myconfig.ini</command> this will read your configuration file + and generate all the base classes, along with the data definition file. + </para> + </refsect1> + <refsect1> + <title>Default Class Definition</title> + <para> + The default generated class looks like this. + <example> + <title>an generated extended class</title> + <programlisting role="php"><![CDATA[ @@ -92,34 +92,48 @@ ]]> - </programlisting> - </example> - </para> - <para> + </programlisting> + </example> + </para> + <para> The class defines the table name, and comments some of table columns for your reference, It also adds the <link linkend="package.database.db-dataobject.db-dataobject.staticget"> <function>staticGet</function></link> method, which can be used to quickly get single rows as Objects. You should add your table related code after the <constant>###END_AUTOCODE</constant>. - </para> - <para> + </para> + <para> The <function>__clone</function> function will only be generated on pre Zend Engine 2 applications, and it is recommended to use it so that your code will be Forward and Backward Compatible with the new engine. - </para> - </refsect1> + </para> + </refsect1> - <refsect1> - <title>Database Definition File</title> - <para> - The default generated database definition file looks like this. - <example> - <title>Database configuration file</title> - <programlisting role="ini"><![CDATA[ + <refsect1> + <title>Database Schema File</title> + <para> + The default generated database definition file looks like this, it is located in the directory set by the + "schema_location" configuration option, and is named the same as the database. + + </para><para> + If you rename the database, you will either have to regenerate the file or copy it to match the same name. + </para><para> + If you change the database schema (eg. add a column or change the type), you will have to regenerate the schema, + using createTables.php, At present, this is not done automatically (although this may be added in the future..) + </para><para> + You should not edit this file by hand (as any changes will be lost when regenerating it). You can override the + keys of a table by using a configuration option "sequence_{table} = keyquot; + + + + + <example> + <title>Database configuration file</title> + <programlisting role="ini"><![CDATA[ [group] id = 1 @@ -137,18 +151,120 @@ id = 1 ]]> - </programlisting> - </example> - </para> - <para> + </programlisting> + </example> + </para> + <para> The blocks indicate either tables and the type of field (1=integer,2=string), or a list of keys for each table. You should not need to edit file. - </para> + </para> - </refsect1> - </refentry> + </refsect1> + + <refsect1> + <title>Alternatives to using a Schema File</title> + <para> + It is possible to use DataObjects without a schema file, this can be achieved in 2 ways + + <itemizedlist> + <listitem> + <simpara>by defining the table() and keys() methods in an extended class</simpara> + </listitem> + <listitem> + <simpara>by passing an array to table() and keys() when you have an instance of dataobjects</simpara> + </listitem> + </itemizedlist> + + The second of this is demostrated on the keys() and tables() page. + </para> + <para> + Below is a hand coded class which does not use a schema.ini file. + </para> + + <para> + It was designed to be a return value from a method, rather than an object variable, so that the output of + print_r(), would not include extra information (and would be smaller when dumping a large result set. + + + <example> + <title>A Hand Coded extended class</title> + <programlisting role="php"><![CDATA[ + + + +/* +* Table Definition for group +*/ + + +class DataObjects_Grp extends DB_DataObject { + + // you can define these yourself + + var $__table='group'; // table name + var $id; // int primary_key + var $name; // string + var $grp_owner; // int + var $official; // string + var $street; // string + var $postcode; // string + var $city; // string + var $homepage; // string + var $email; // string + var $extra; // blob + + + // these are usefull to be consistant with a autogenerated file. + + /* ZE2 compatibility trick */ + function __clone() { return $this;} + + /* Static get */ + function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Grp',$k,$v); } + + + // now define your table structure. + // key is column name, value is type + function table() { + array( + 'id' => DB_DATAOBJECT_INT, + 'name' => DB_DATAOBJECT_STR, + 'bday' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE, + 'last' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, + 'active' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL, + 'desc' => DB_DATAOBJECT_STR + DB_DATAOBJECT_TXT, + 'photo' => DB_DATAOBJECT_STR + DB_DATAOBJECT_BLOB, + )); + } + + // now define the keys. + function keys() { + return array('id'); + } + + + +} + + +]]> + </programlisting> + </example> + </para> + <para> + + The blocks indicate either tables and the type of field (1=integer,2=string), + or a list of keys for each table. You should not need to edit file. + + </para> + + </refsect1> + + + +</refentry> <!-- Keep this comment at the end of the file Local variables: Index: peardoc/en/package/database/db-dataobject/intro-configuration.xml diff -u peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.6 peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.7 --- peardoc/en/package/database/db-dataobject/intro-configuration.xml:1.6 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-configuration.xml Tue Nov 11 08:50:49 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <refentry id="package.database.db-dataobject.intro-configuration"> <refnamediv> @@ -149,6 +149,43 @@ <variablelist> + <varlistentry> + <term> + <parameter>sequence_{table}</parameter> + <type>string</type> + </term> + <listitem> + <para> + To Hard code the key (autoincrement/nextval() for a table to a specific key ,overriding anything in the keys + definition of the file. Normally used on databases that are not able to be queried correctly for their structure + <example> + <title> using login as the key for the person table</title> + <programlisting role="ini"><![CDATA[ + + +sequence_person = login + + + + ]]></programlisting> + </example> + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term> + <parameter>ignore_sequence_keys</parameter> + <type>string</type> + </term> + <listitem> + <para> + If you do not want to use pear's nextval(), for automatically filling in sequences, this can disable it for + "ALL", or a list of tables "person,cart,group" + </para> + </listitem> + </varlistentry> + <varlistentry> <term> <parameter>debug</parameter> Index: peardoc/en/package/database/db-dataobject/intro-filters.xml diff -u peardoc/en/package/database/db-dataobject/intro-filters.xml:1.2 peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 --- peardoc/en/package/database/db-dataobject/intro-filters.xml:1.2 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-filters.xml Tue Nov 11 08:50:49 2003 @@ -1,8 +1,8 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.database.db-dataobject.intro-filters"> <refnamediv> - <refname>Advanced Filters</refname> + <refname>Selecting Specific data (SELECT)</refname> <refpurpose> Advanced Filters - ::query(), ::SelectAdd(), ::whereAdd(), ::Limit(), ::OrderBy(), ::GroupBy(), </refpurpose>