Class: DB_Table_Generator
Source Location: /DB_Table-1.5.0RC2/DB/Table/Generator.php
class DB_Table_Generator - Generates DB_Table subclass skeleton code
Author(s):
Version:
- $Id: Generator.php,v 1.9 2007/03/23 10:32:43 morse Exp $
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 144]
class DB_Table_Generator - Generates DB_Table subclass skeleton code This class generates the php code necessary to use the DB_Table package to interact with an existing database. This requires the generation of a skeleton subclass definition be generated for each table in the database, in which the $col, $idx, and $auto_inc_col properties are constructed using a table schema that is obtained by querying the database. The class can also generate a file, named 'Database.php' by default, that includes (require_once) each of the table subclass definitions, instantiates one object of each DB_Table subclass (i.e., one object for each table), instantiates a parent DB_Table_Database object, adds all the tables to that parent, attempts to guess foreign key relationships between tables based on the column names, and adds the inferred references to the parent object. All of the code is written to a directory whose path is given by the property $class_write_path. By default, this is the current directory. By default, the name of the class constructed for a table named 'thing' is "Thing_Table". That is, the class name is the table name, with the first letter upper case, with a suffix '_Table'. This suffix can be changed by setting the $class_suffix property. The file containing a subclass definition is the subclass name with a php extension, e.g., 'Thing_Table.php'. The object instantiated from that subclass is the same as the table name, with no suffix, e.g., 'thing'. To generate the code for all of the tables in a database named $database, instantiate a MDB2 or DB object named $db that connects to the database of interest, and execute the following code:
Here $class_write_path should be the path (without a trailing separator) to a directory in which all of the code should be written. If this directory does not exist, it will be created. If the directory does already exist, exising files will not be overwritten. If $class_write_path is not set (i.e., if this line is omitted) all the code will be written to the current directory. If ->generateDatabaseFile() is called, it must be called after ->generateTableClassFiles(). By default, ->generateTableClassFiles() and ->generateDatabaseFiles() generate code for all of the tables in the current database. To generate code for a specified list of tables, set the value of the public $tables property to a sequential list of table names before calling either of these methods. Code can be generated for three tables named 'table1', 'table2', and 'table3' as follows:
$generator->tables = array ('table1', 'table2', 'table3');
If the $tables property is not set to a non-null value prior to calling ->generateTableClassFiles() then, by default, the database is queried for a list of all table names, by calling the ->getTableNames() method from within ->generateTableClassFiles(). PHP version 4 and 5
Class Variables
$auto_inc_col = array()
[line 279]
Array of auto_increment column names Array $this->auto_inc_col[table_name] = auto-increment column
$class_include_path = ''
[line 245]
Include path to subclass definition files from database file Used to create require_once statements in the Database.php file, which is in the same directory as the class definition files. Leave as empty string if your PHP include_path contains ".". The value should not include a trailing "/", which is added automatically to values other than the empty string.
$class_suffix = "_Table"
[line 221]
Suffix to add to table names to obtain corresponding class names
$class_write_path = ''
[line 231]
Path to directory in which subclass definitions should be written Value should not include a trailing "/".
$col = array()
[line 257]
Array of column definitions Array $this->col[table_name][column_name] = column definition. Column definition is an array with the same format as the $col property of a DB_Table object
$error = null
[line 189]
If there is an error on instantiation, this captures that error. This property is used only for errors encountered in the constructor at instantiation time. To check if there was an instantiation error...
// ... error handling code here ...
}
$extends = 'DB_Table'
[line 205]
Class being extended (DB_Table or generic subclass)
$extends_file = 'DB/Table.php'
[line 213]
Path to definition of the class $this->extends
$idx = array()
[line 269]
Array of index/constraint definitions. Array $this->idx[table_table][index_name] = Index definition. The index definition is an array with the same format as the DB_Table $idx property property array.
$idxname_format = '%s'
[line 296]
MDB2 'idxname_format' option, format of index names For use in printf() formatting. Use '%s' to use index names as returned by getTableConstraints/Indexes, and '%s_idx' to add an '_idx' suffix. For MySQL, use the default value '%'.
$name = null
[line 155]
Name of the database
$primary_key = array()
[line 287]
Array of primary keys
$tables = array()
[line 197]
Numerical array of table name strings
Method Detail
Documentation generated on Mon, 11 Mar 2019 14:57:42 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|
|