Getting Started |
AXMLS consists of two parts: the schema description, or DTD, and the PHP class that manipulates and parses the schema. This document introduces the reader to many to many of the tools AXMLS provides to manage and manipulate a schema.
Executing the SchemaAXMLS provides two different methods for applying the SQL resulting from a parsed schema to the database: inline execution and post execution. Use the ContinueOnError() method to specify whether or not database execution should attempt to continue if an error occurs.
Inline Execution applies each schema entity to the database immediately after that entity is parsed. I.e., the first table is read from the schema and applied to the database, then the second table, etc.
$schema = new adoSchema( $this->dbconn ); // Inline Execution $schema->ContinueOnError( TRUE ); $schema->ExecuteInline( TRUE ); $schema->ParseSchemaFile( "schema.xml" );
Post Execution parses the entire database and then applies all of the resulting SQL statements to the database in order.
$schema = new adoSchema( $this->dbconn ); // Post Execution (default) $schema->executeInline( FALSE ); $schema->ParseSchemaFile( "schema.xml" ); $schema->ExecuteSchema();
If successful, either method will build or upgrade the database.
Upgrading an Existing DatabaseUpgrading a database is as simple as creating one. To upgrade an existing database to a new version of a schema, simply parse and execute the schema as above. AXMLS will automatically upgrade all tables and indices to match those provided in the schema.
Object PrefixingIn a world of pluggable and reusable code, multple applications often coexist in a single database. Object prefixes allow you to create a namespace for your application. For example, an application called Tackle might want to prefix all its tables and objects with tackle_ so they'll be less likely to confict with other applications that share the database. AXMLS's setPrefix() method provides this capability.
Getting at the SQL$schema = new adoSchema( $this->dbconn ); // Set the prefix for database objects (before parsing) $schema->setPrefix( 'tackle' );
AXMLS provides several tools for accessing the SQL created by the schema parser. Calling PrintSQL() returns the parsed SQL in HTML, text, or PHP array format. Calling SaveSQL() saves the parsed SQL to the specified file.
$schema->ParseSchemaFile( "schema.xml" ); $schema->ExecuteSchema(); print( $schema->PrintSQL( 'TEXT' ); // Display SQL as text print( $schema->PrintSQL( 'HTML' ); // Display SQL as HTML $sql = $schema->PrintSQL(); // Fetch SQL as array // Save SQL to file $schema->SaveSQL( 'schema.sql' );
As always, see the Class Documentation for detailed information about the methods.
Getting Started |
Documentation generated on Tue, 27 Jul 2004 20:05:45 -0400 by phpDocumentor 1.3.0RC3