ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:axmls:axmls_index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:axmls:axmls_index [2016/01/13 16:11] mnewnhamv5:axmls:axmls_index [2020/01/13 15:52] (current) – Remove separator line dregad
Line 1: Line 1:
-<WRPA right box>+<WRAP right box>
 [[v5:axmls:Index]]\\ [[v5:axmls:Index]]\\
 </WRAP> </WRAP>
 ======= ADOdb-xmlschema ====== ======= ADOdb-xmlschema ======
-~~NOTOC~~+
 <WRAP right box round 300px> <WRAP right box round 300px>
 ==See also== ==See also==
Line 29: Line 29:
 </WRAP>  </WRAP>
 ===== Installation ===== ===== Installation =====
-This feature is included in the standard release+This feature is included in the standard release.
 ===== Using AXMLS in Your Application ===== ===== Using AXMLS in Your Application =====
 There are two steps involved in using AXMLS in your application: first, you must create a schema, or XML representation of your database, and second, you must create the PHP code that will parse and execute the schema. There are two steps involved in using AXMLS in your application: first, you must create a schema, or XML representation of your database, and second, you must create the PHP code that will parse and execute the schema.
Line 39: Line 39:
 <?xml version="1.0"?> <?xml version="1.0"?>
 <schema version="0.3"> <schema version="0.3">
- 
   <table name="users">   <table name="users">
-    <desc>A typical users table for our application.</desc>+    <descr>A typical users table for our application.</descr>
     <field name="userId" type="I">     <field name="userId" type="I">
       <descr>A unique ID assigned to each user.</descr>       <descr>A unique ID assigned to each user.</descr>
       <KEY/>       <KEY/>
       <AUTOINCREMENT/>       <AUTOINCREMENT/>
-    </field> +    </field> 
-    +
     <field name="userName" type="C" size="16"><NOTNULL/></field>     <field name="userName" type="C" size="16"><NOTNULL/></field>
-     
     <index name="userName">     <index name="userName">
       <descr>Put a unique index on the user name</descr>       <descr>Put a unique index on the user name</descr>
Line 56: Line 53:
     </index>     </index>
   </table>   </table>
-   
   <sql>   <sql>
     <descr>Insert some data into the users table.</descr>     <descr>Insert some data into the users table.</descr>
Line 65: Line 61:
 </code> </code>
  
-Let's take a detailed look at this schema. The opening ''<?xml version="1.0"?>'' tag is  required by XML. The <schema> tag tells the parser that the enclosed markup defines an XML schema. The version="0.3" attribute sets the version of the AXMLS DTD used by the XML schema All versions of AXMLS prior to version 1.0 have a schema version of "0.1". The current schema version is "0.3".+Let's take a detailed look at this schema. The opening ''<?xml version="1.0"?>'' tag is required by XML. The <schema> tag tells the parser that the enclosed markup defines an XML schema. The version="0.3" attribute sets the version of the AXMLS DTD used by the XML schema. The current schema version is "0.3".
  
 <code xml> <code xml>
Line 78: Line 74:
 <code xml> <code xml>
 <table name="users"> <table name="users">
- +    <descr>A typical users table for our application.</descr>
-    <desc>A typical users table for our application.</desc>+
     <field name="userId" type="I">     <field name="userId" type="I">
       <descr>A unique ID assigned to each user.</descr>       <descr>A unique ID assigned to each user.</descr>
Line 85: Line 80:
       <AUTOINCREMENT/>       <AUTOINCREMENT/>
     </field>     </field>
-     
     <field name="userName" type="C" size="16"><NOTNULL/></field>     <field name="userName" type="C" size="16"><NOTNULL/></field>
-     
 </table> </table>
 </code> </code>
Line 93: Line 86:
 This table is called "users" and has a description and two fields: This table is called "users" and has a description and two fields:
  
-  * The description is optional, and is currently  only for your own information; it is not applied to the database. +  * The description is optional, and is currently only for your own information; it is not (yet) applied to the database.
   * The first <field> tag will create a field named "userId" of type "I", or integer. (See the ADOdb Data Dictionary documentation for a list of valid types.) This <field> tag encloses two special field options: <KEY/>, which specifies this field as a primary key, and <AUTOINCREMENT/>, which specifies that the database engine should automatically fill this field with the next available value when a new row is inserted.    * The first <field> tag will create a field named "userId" of type "I", or integer. (See the ADOdb Data Dictionary documentation for a list of valid types.) This <field> tag encloses two special field options: <KEY/>, which specifies this field as a primary key, and <AUTOINCREMENT/>, which specifies that the database engine should automatically fill this field with the next available value when a new row is inserted. 
   * The second <field> tag will create a field named "userName" of type "C", or character, and of length 16 characters. The <NOTNULL/> option specifies that this field does not allow NULLs.   * The second <field> tag will create a field named "userName" of type "C", or character, and of length 16 characters. The <NOTNULL/> option specifies that this field does not allow NULLs.
Line 104: Line 97:
 <table name="users"> <table name="users">
   ...   ...
-     
   <index name="userName">   <index name="userName">
     <descr>Put a unique index on the user name</descr>     <descr>Put a unique index on the user name</descr>
     <col>userName</col>     <col>userName</col>
     <UNIQUE/>     <UNIQUE/>
-  </index> +  </index> 
-    +
 </table> </table>
 </code> </code>
Line 122: Line 113:
 <sql> <sql>
   <descr>Insert some data into the users table.</descr>   <descr>Insert some data into the users table.</descr>
-  <query>insert into users (userName) values ( 'admin' )</query> +  <query>insert into users (userName) values ('admin')</query> 
-  <query>insert into users (userName) values ( 'Joe' )</query>+  <query>insert into users (userName) values ('Joe')</query>
 </sql> </sql>
 </code> </code>
Line 153: Line 144:
 /* Start by creating a normal ADODB connection. /* Start by creating a normal ADODB connection.
  */  */
-$db = ADONewConnection( $platform ); +$db = ADONewConnection($platform); 
-$db->Connect( $dbHost, $dbUser, $dbPassword, $dbName );+$db->connect($dbHost, $dbUser, $dbPassword, $dbName);
  
 /* Use the database connection to create a new adoSchema object. /* Use the database connection to create a new adoSchema object.
  */  */
-$schema = new adoSchema( $db );+$schema = new adoSchema($db);
  
-/* Call ParseSchema() to build SQL from the XML schema file. +/* Call parseSchema() to build SQL from the XML schema file. 
- * Then call ExecuteSchema() to apply the resulting SQL to + * Then call executeSchema() to apply the resulting SQL to 
  * the database.  * the database.
  */  */
-$sql = $schema->ParseSchema( $schemaFile ); +$sql = $schema->parseSchema($schemaFile); 
-$result = $schema->ExecuteSchema();+$result = $schema->executeSchema();
 </code> </code>
  
Line 171: Line 162:
  
 <code php> <code php>
-$db = ADONewConnection( 'mysql' ); +$db = ADONewConnection($platform); 
-$db->Connect'host''user''password''database' );+$db->connect($dbHost$dbUser$dbPassword$dbName);
 </code> </code>
  
Line 178: Line 169:
  
 <code php> <code php>
-$schema = new adoSchema( $db );+$schema = new adoSchema($db);
 </code> </code>
  
-Third, call ParseSchema() to parse the schema and then ''executeSchema()'' to apply it to the database. You must pass ''parseSchema()'' the path and filename of your schema file.+Third, call parseSchema() to parse the schema and then ''executeSchema()'' to apply it to the database. You must pass ''parseSchema()'' the path and filename of your schema file.
  
 <code php> <code php>
-$schema->ParseSchema( $schemaFile );  +$schema->parseSchema($schemaFile);  
-$schema->ExecuteSchema(); +$schema->executeSchema(); 
 </code> </code>
  
Line 195: Line 186:
 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 of the tools AXMLS provides to manage and manipulate a schema. 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 of the tools AXMLS provides to manage and manipulate a schema.
 ==== Executing the Schema ==== ==== Executing the Schema ====
-AXMLS provides two different methods for applying the SQL resulting from a parsed schema to the  database: **inline execution** and **post execution**. Use the [[v5:axmls:continueonerror|ContinueOnError()]] method to specify whether or not database execution should attempt to continue if an error occurs.+AXMLS provides two different methods for applying the SQL resulting from a parsed schema to the  database: **inline execution** and **post execution**. Use the [[v5:axmls:continueonerror|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. **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.
  
 <code php> <code php>
-$schema = new adoSchema( $this->dbconn );+$schema = new adoSchema($this->dbconn);
  
 // Inline Execution // Inline Execution
-$schema->ContinueOnErrorTRUE ); +$schema->continueOnError(true); 
-$schema->ExecuteInlineTRUE ); +$schema->executeInline(true); 
-$schema->ParseSchemaFile"schema.xml);+$schema->parseSchemaFile('schema.xml');
 </code> </code>
  
Line 211: Line 202:
  
 <code php> <code php>
-$schema = new adoSchema( $this->dbconn );+$schema = new adoSchema($this->dbconn);
  
 // Post Execution (default) // Post Execution (default)
-$schema->executeInline( FALSE ); +$schema->executeInline(false); 
-$schema->ParseSchemaFile"schema.xml); +$schema->parseSchemaFile('schema.xml'); 
-$schema->ExecuteSchema();+$schema->executeSchema();
 </code> </code>
  
Line 226: Line 217:
  
 <code php> <code php>
-$schema = new adoSchema( $this->dbconn );+$schema = new adoSchema($this->dbconn);
  
 // Set the prefix for database objects (before parsing) // Set the prefix for database objects (before parsing)
-$schema->setPrefix( 'tackle' );+$schema->setPrefix('tackle');
 </code> </code>
 ==== Getting at the SQL ==== ==== Getting at the SQL ====
Line 236: Line 227:
  
 <code php> <code php>
-$schema->parseSchemaFile( "schema.xml);+$schema->parseSchemaFile('schema.xml');
 $schema->executeSchema(); $schema->executeSchema();
  
-print$schema->printSQL( 'TEXT' ); // Display SQL as text +print $schema->printSQL('TEXT'); // Display SQL as text 
-print$schema->printSQL( 'HTML' ); // Display SQL as HTML+print $schema->printSQL('HTML'); // Display SQL as HTML
 $sql = $schema->printSQL(); // Fetch SQL as array $sql = $schema->printSQL(); // Fetch SQL as array
  
 // Save SQL to file // Save SQL to file
-$schema->saveSQL( 'schema.sql' );+$schema->saveSQL('schema.sql');
 </code> </code>
 As always, see the Class Documentation for detailed information about the methods. As always, see the Class Documentation for detailed information about the methods.
v5/axmls/axmls_index.1452697882.txt.gz · Last modified: 2017/04/21 11:23 (external edit)