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 revision Previous revision
Next revision
Previous revision
v5:axmls:axmls_index [2018/07/01 22:15]
peterdd prefer functions start lowercase (#430)
v5:axmls:axmls_index [2020/01/13 15:52] (current)
dregad Remove separator line
Line 3: Line 3:
 </​WRAP>​ </​WRAP>​
 ======= ADOdb-xmlschema ====== ======= ADOdb-xmlschema ======
------------------------------------ +
-~~NOTOC~~+
 <WRAP right box round 300px> <WRAP right box round 300px>
 ==See also== ==See also==
Line 30: 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 40: 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 57: 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 66: 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 79: 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 86: 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 94: 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 105: 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 123: 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 154: 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 172: 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 179: 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 201: Line 191:
  
 <code php> <code php>
-$schema = new adoSchema( $this->​dbconn );+$schema = new adoSchema($this->​dbconn);​
  
 // Inline Execution // Inline Execution
-$schema->​continueOnError( ​TRUE ); +$schema->​continueOnError(true); 
-$schema->​executeInline( ​TRUE ); +$schema->​executeInline(true); 
-$schema->​parseSchemaFile( ​"schema.xml" ​);+$schema->​parseSchemaFile('schema.xml');
 </​code>​ </​code>​
  
Line 212: 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 227: 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 237: 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.1530476113.txt.gz · Last modified: 2018/07/01 22:15 by peterdd