Reverse Module
Описание
The Reverse module is an extension of the Common Module driver, and is made up in the following structure:
Common driver file that encapsulates an API that can be used to execute the reverse driver queries.
A set of DBMS specific drivers that are specifically written against the supported database back end (e.g. mysql.php for MySQL, and pgsql.php for PostgreSQL)
Usage
In order to use the MDB2 Reverse drivers, it is necessary to first load the Reverse driver into your MDB2 instance. Lets start a MDB2 instance and set up our connection:
Пример 35-1. Loading the Reverse module
|
Пример 35-2. Create a table
|
getTableFieldDefinition() Method
The getTableFieldDefinition() Method exists primarily to get an array that defines a table field. This array can then be used to re-create the table elsewhere, or for any other purpose that may be necessary. Using the MDB2 instance defined above, we will connect to a database, define a table that we want to work with, and reverse engineer a specific field that we are interested in. First, we need to define the table and field that we want to work with; then, it is as easy as a single line of code to get the table definition back as an array of mixed values, then using var_dump to view the results:
Пример 35-3. Get the table definition
|
array(1) { [0] => array(5) { ['notnull'] => bool(false) ['nativetype'] => string(4) "date" ['default'] => NULL ['type'] => string(4) "date" ['mdb2type'] => string(4) "date" } } |
Additional table information
A number of other methods exist to gain information about a selected table. You may use any of the following methods according to the information needed:
getTableIndexDefinition(): - requires a table name and an index name to return information about the table index as an array
getTableConstraintDefinition(): requires a table name and a constraint to query against. This will return any constraint definitions that exist on the table. A constraint as is defined here is usually a Primary Key or an Unique Key
getSequenceDefinition(): requires a sequence name. It will return information about the existing table sequence. The method will return an array on success or an MDB2 error on failure.
getTriggerDefinition(): takes a trigger name as an argument, and will return information as an array on the trigger queried.
tableInfo() Method
This method will return a lot of information regarding a table, and can be used in a number of different ways. The information that it returns will differ slightly across different RDBM's and may give some variance in results. This method can be used to query either a table definition, or a resultset, which makes it great for creating optimized tables. The tableInfo() method allows you to pass a parameter for the mode that you would like to see the results presented as. In order to demonstrate the results more effectively, we will use a series of examples to do some queries and return the results in different modes. NOTE: Either a table OR a resultset can be passed as the first parameter to get information on the table. In these examples, we will be using the table that we defined above.
Пример 35-4. tableinfo() usage 1
|
Пример 35-5. tableinfo() usage 2
|
NOTE: The flags element will contain a space-separated list of additional information about the field. This data is inconsistent between DBMS's due to the way each DBMS works:
primary_key
unique_key
multiple_key
not_null
unsigned
Пред. | Начало | След. |
Manager Module | Уровень выше | autoPrepare & autoExecute |