# adodb-xmlschema

Written by Richard Tango-Lowy.

For more information, contact richtl@arscognita.com or visit our site at www.arscognita.com.

At the moment, you should report bugs by mailing them to me. (If I can't convince John to make this part of ADODB :-), I'll create a project for it on SourceForge.)

## Introduction

adodb-xmlschema is a class that allows the user to quickly and easily build a database on any ADOdb-supported platform using a simple XML format.

This library is dual-licensed under a BSD-style license and under the GNU Lesser Public License. See the LICENSE file for more information.

## Features

- Darned easy to install
- Quickly to create schemas that build on any platform supported by ADODB.

## Installation

To install adodb-xmlschema, simply copy the `adodb-xmlschema.php` file into your ADODB directory.

## Quick Start

First, create an XML database schema. Let's call it "schema.xml:"

    <?xml version="1.0"?>
    <schema>
      <table name="mytable">
        <field name="row1" type="I">
          <descr>An integer row that's a primary key and autoincrements</descr>
          <KEY/>
          <AUTOINCREMENT/>
        </field>
        <field name="row2" type="C" size="16">
          <descr>A 16 character varchar row that can't be null</descr>
          <NOTNULL/>
        </field>
      </table>
      <index name="myindex" table="mytable">
        <col>row1</col>
        <col>row2</col>
      </index>
      <sql>
        <descr>SQL to be executed only on specific platforms</descr>
        <query platform="postgres|postgres7">
          insert into mytable ( row1, row2 ) values ( 12, 'stuff' )
        </query>
        <query platform="mysql">
          insert into mytable ( row1, row2 ) values ( 12, 'different stuff' )
        </query>
      </sql>
    </schema>

Create a new database using the appropriate tool for your platform. Executing the following PHP code will create the a mytable and myindex in the database and insert two rows into mytable.

    // To build the schema, start by creating a normal ADOdb connection:
    $db->NewADOConnection( 'mysql' );
    $db->Connect( ... );

    // Create the schema object and build the query array.
    $schema = new adoSchema( $db );

    // Build the SQL array
    $sql = $schema->ParseSchema( "schema.xml" );

    // Execute the SQL on the database
    $result = $schema->ExecuteSchema( $sql );

    // Finally, clean up after the XML parser
    // (PHP won't do this for you!)
    $schema->Destroy();

## XML Schema Format:

(See ADOdb_schema.dtd for the full specification)

    <?xml version="1.0"?>
    <schema>
      <table name="tablename" platform="platform1|platform2|...">
        <descr>Optional description</descr>
        <field name="fieldname" type="datadict_type" size="size">
          <KEY/>
          <NOTNULL/>
          <AUTOINCREMENT/>
          <DEFAULT value="value"/>
        </field>
    	... more fields
      </table>
      ... more tables

      <index name="indexname" platform="platform1|platform2|...">
        <descr>Optional description</descr>
        <col>fieldname</col>
        ... more columns
      </index>
      ... more indices

      <sql platform="platform1|platform2|...">
        <descr>Optional description</descr>
        <query platform="platform1|platform2|...">SQL query</query>
        ... more queries
      </sql>
      ... more SQL
      </schema>

## Thanks

Thanks to John Lim for giving us ADODB, and for the hard work that keeps it on top of things. And particulary for the datadict code that made xmlschema possible.

And to the kind folks at PHP Documentor. Cool tool.

And to Linus. I thought the end of Amiga was the end of computing. Guess I was wrong :-)

`$Id: package_xmlschema.html,v 1.1 2003/10/25 05:59:54 moodler Exp $`