Written by Richard Tango-Lowy.
For more information, contact richtl@arscognita.com or visit our site at www.arscognita.com.
To report bugs or enhancements, or to download the latest version, visit the adodb-xmlschema Sourceforge Project Page.
adodb-xmlschema is a class that allows the user to quickly and easily build a database using the excellent ADODB database library and a simple XML formatted file.
This library is dual-licensed under a BSD-style license and under the GNU Lesser Public License. See the LICENSE file for more information.
To install adodb-xmlschema, simply copy the adodb-xmlschema.inc.php file into your ADODB directory.
See the online documentation in the docs directory.
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 one row into mytable if the platform is postgres or mysql.
// 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 ); // Optionally, set a prefix for newly-created tables. In this example // the prefix "myprefix_" will result in a table named "myprefix_tablename". //$schema->setPrefix( "myprefix_" ); // 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();
(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 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 Mike Benoit (http://phpgacl.sourceforge.net) for a recent patch or two and some good ideas.
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.2 2003/07/14 20:31:18 richtl Exp $