[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/adodb/docs/ -> docs-datadict.htm (source)

   1  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   2  <html>
   3  <head>
   4    <title>ADOdb Data Dictionary Manual</title>
   5    <meta http-equiv="Content-Type"
   6   content="text/html; charset=iso-8859-1">
   7    <style type="text/css">
   8        body, td {
   9          /*font-family: Arial, Helvetica, sans-serif;*/
  10          font-size: 11pt;
  11        }
  12        pre {
  13          font-size: 9pt;
  14           background-color: #EEEEEE; padding: .5em; margin: 0px; 
  15        }
  16        .toplink {
  17          font-size: 8pt;
  18        }
  19      </style>
  20  </head>
  21  <body style="background-color: rgb(255, 255, 255);">
  22  <h2>ADOdb Data Dictionary Library for PHP</h2>
  23  <p>V4.94 23 Jan 2007 (c) 2000-2007 John Lim (<a
  24   href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a>).<br>
  25  AXMLS (c) 2004 ars Cognita, Inc</p>
  26  <p><font size="1">This software is dual licensed using BSD-Style and
  27  LGPL. This means you can use it in compiled proprietary and commercial
  28  products.</font></p>
  29  
  30  <p>Useful ADOdb links: <a href="http://adodb.sourceforge.net/#download">Download</a>
  31  &nbsp; <a href="http://adodb.sourceforge.net/#docs">Other Docs</a>
  32  </p>
  33  <p>This documentation describes a PHP class library to automate the
  34  creation of tables, indexes and foreign key constraints portably for
  35  multiple databases. Richard Tango-Lowy and Dan Cech have been kind
  36  enough to contribute <a href="#xmlschema">AXMLS</a>, an XML schema
  37  system for defining databases. You can contact them at
  38  dcech#phpwerx.net and richtl#arscognita.com.</p>
  39  <p>Currently the following databases are supported:</p>
  40  <p> <b>Well-tested:</b> PostgreSQL, MySQL, Oracle, MSSQL.<br>
  41  <b>Beta-quality:</b> DB2, Informix, Sybase, Interbase, Firebird.<br>
  42  <b>Alpha-quality:</b> MS Access (does not support DEFAULT values) and
  43  generic ODBC.
  44  </p>
  45  <h3>Example Usage</h3>
  46  <pre>  include_once ('adodb.inc.php');<br>  <font color="#006600"># First create a normal connection</font><br>  $db = NewADOConnection('mysql');<br>  $db-&gt;Connect(...);<br><br>  <font
  47   color="#006600"># Then create a data dictionary object, using this connection</font><br>  $dict = <strong>NewDataDictionary</strong>($db);<br><br>  <font
  48   color="#006600"># We have a portable declarative data dictionary format in ADOdb, similar to SQL.<br>  # Field types use 1 character codes, and fields are separated by commas.<br>  # The following example creates three fields: "col1", "col2" and "col3":</font><br>  $flds = " <br>  <font
  49   color="#663300"><strong> col1 C(32) NOTNULL DEFAULT 'abc',<br>   col2 I  DEFAULT 0,<br>   col3 N(12.2)</strong></font><br>  ";<br><br>  <font
  50   color="#006600"># We demonstrate creating tables and indexes</font><br>  $sqlarray = $dict-&gt;<strong>CreateTableSQL</strong>($tabname, $flds, $taboptarray);<br>  $dict-&gt;<strong>ExecuteSQLArray</strong>($sqlarray);<br><br>  $idxflds = 'co11, col2';<br>  $sqlarray = $dict-&gt;<strong>CreateIndexSQL</strong>($idxname, $tabname, $idxflds);<br>  $dict-&gt;<strong>ExecuteSQLArray</strong>($sqlarray);<br></pre>
  51  <h3>More Complex Table Sample</h3>
  52  <p>
  53  The following string will create a table with a primary key event_id and multiple indexes, including one compound index idx_ev1. The ability to define indexes using the INDEX keyword was added in ADOdb 4.94 by Gaetano Giunta.
  54  <pre>
  55  $flds = "
  56    event_id I(11) NOTNULL AUTOINCREMENT PRIMARY,
  57    event_type I(4) NOTNULL  <b>INDEX idx_evt</b>,
  58    event_start_date T DEFAULT NULL <b>INDEX id_esd</b>,
  59    event_end_date T DEFAULT '0000-00-00 00:00:00' <b>INDEX id_eted</b>,
  60    event_parent I(11) UNSIGNED NOTNULL DEFAULT 0 <b>INDEX id_evp</b>,
  61    event_owner I(11) DEFAULT 0 <b>INDEX idx_ev1</b>,
  62    event_project I(11) DEFAULT 0 <b>INDEX idx_ev1</b>,
  63    event_times_recuring I(11) UNSIGNED NOTNULL DEFAULT 0,
  64    event_icon C(20) DEFAULT 'obj/event',
  65    event_description X
  66  ";
  67  $sqlarray = $db-><b>CreateTableSQL</b>($tablename, $flds);
  68  $dict-><b>ExecuteSQLArray</b>($sqlarray);
  69  </pre>
  70  <h3>Class Factory</h3>
  71  <h4>NewDataDictionary($connection, $drivername=false)</h4>
  72  <p>Creates a new data dictionary object. You pass a database connection object in $connection. The $connection does not have to be actually connected to the database. Some database connection objects are generic (eg. odbtp and odbc). Since 4.53, you can tell ADOdb  the actual database with $drivername. E.g.</p>
  73  <pre>
  74  $db =& NewADOConnection('odbtp');
  75  $datadict = NewDataDictionary($db, 'mssql'); # force mssql
  76  </pre>
  77  <h3>Class Functions</h3>
  78  <h4>function CreateDatabase($dbname, $optionsarray=false)</h4>
  79  <p>Create a database with the name $dbname;</p>
  80  <h4>function CreateTableSQL($tabname, $fldarray, $taboptarray=false)</h4>
  81  <pre>  RETURNS:      an array of strings, the sql to be executed, or false<br>  $tabname:     name of table<br>  $fldarray:    string (or array) containing field info<br>  $taboptarray: array containing table options<br></pre>
  82  <p>The new format of $fldarray uses a free text format, where each
  83  field is comma-delimited.
  84  The first token for each field is the field name, followed by the type
  85  and optional
  86  field size. Then optional keywords in $otheroptions:</p>
  87  <pre>  "$fieldname $type $colsize $otheroptions"</pre>
  88  <p>The older (and still supported) format of $fldarray is a
  89  2-dimensional array, where each row in the 1st dimension represents one
  90  field. Each row has this format:</p>
  91  <pre>  array($fieldname, $type, [,$colsize] [,$otheroptions]*)</pre>
  92  <p>The first 2 fields must be the field name and the field type. The
  93  field type can be a portable type codes or the actual type for that
  94  database.</p>
  95  <p>Legal portable type codes include:</p>
  96  <pre>  C:  Varchar, capped to 255 characters.<br>  X:  Larger varchar, capped to 4000 characters (to be compatible with Oracle). <br>  XL: For Oracle, returns CLOB, otherwise the largest varchar size.<br><br>  C2: Multibyte varchar<br>  X2: Multibyte varchar (largest size)<br><br>  B:  BLOB (binary large object)<br><br>  D:  Date (some databases do not support this, and we return a datetime type)<br>  T:  Datetime or Timestamp<br>  L:  Integer field suitable for storing booleans (0 or 1)<br>  I:  Integer (mapped to I4)<br>  I1: 1-byte integer<br>  I2: 2-byte integer<br>  I4: 4-byte integer<br>  I8: 8-byte integer<br>  F:  Floating point number<br>  N:  Numeric or decimal number<br></pre>
  97  <p>The $colsize field represents the size of the field. If a decimal
  98  number is used, then it is assumed that the number following the dot is
  99  the precision, so 6.2 means a number of size 6 digits and 2 decimal
 100  places. It is recommended that the default for number types be
 101  represented as a string to avoid any rounding errors.</p>
 102  <p>The $otheroptions include the following keywords (case-insensitive):</p>
 103  <pre>  AUTO            For autoincrement number. Emulated with triggers if not available.<br>                  Sets NOTNULL also.<br>  AUTOINCREMENT   Same as auto.<br>  KEY             Primary key field. Sets NOTNULL also. Compound keys are supported.<br>  PRIMARY         Same as KEY.<br>  DEF             Synonym for DEFAULT for lazy typists.<br>  DEFAULT         The default value. Character strings are auto-quoted unless<br>                  the string begins and ends with spaces, eg ' SYSDATE '.<br>  NOTNULL         If field is not null.<br>  DEFDATE         Set default value to call function to get today's date.<br>  DEFTIMESTAMP    Set default to call function to get today's datetime.<br>  NOQUOTE         Prevents autoquoting of default string values.<br>  CONSTRAINTS     Additional constraints defined at the end of the field<br>                  definition.<br></pre>
 104  <p>The Data Dictonary accepts two formats, the older array
 105  specification:</p>
 106  <pre>  $flds = array(<br>    array('COLNAME',   'DECIMAL', '8.4', 'DEFAULT' =&gt; 0, 'NOTNULL'),<br>    array('id',        'I'      , 'AUTO'),<br>    array('`MY DATE`', 'D'      , 'DEFDATE'),<br>    array('NAME',      'C'      , '32', 'CONSTRAINTS' =&gt; 'FOREIGN KEY REFERENCES reftable')<br>  );<br></pre>
 107  <p>Or the simpler declarative format:</p>
 108  <pre>  $flds = "<font color="#660000"><strong><br>    COLNAME DECIMAL(8.4) DEFAULT 0 NOTNULL,<br>    id I AUTO,<br>    `MY DATE` D DEFDATE,<br>    NAME C(32) CONSTRAINTS 'FOREIGN KEY REFERENCES reftable'</strong></font><br>  ";<br></pre>
 109  <p>Note that if you have special characters in the field name (e.g. My
 110  Date), you should enclose it in back-quotes. Normally field names are
 111  not case-sensitive, but if you enclose it in back-quotes, some
 112  databases will treat the names as case-sensitive (eg. Oracle) , and
 113  others won't. So be careful.</p>
 114  <p>The $taboptarray is the 3rd parameter of the CreateTableSQL
 115  function. This contains table specific settings. Legal keywords include:</p>
 116  <ul>
 117    <li><b>REPLACE</b><br>
 118  Indicates that the previous table definition should be removed
 119  (dropped)together with ALL data. See first example below. </li>
 120    <li><b>DROP</b><br>
 121  Drop table. Useful for removing unused tables. </li>
 122    <li><b>CONSTRAINTS</b><br>
 123  Define this as the key, with the constraint as the value. See the
 124  postgresql <a href="#foreignkey">example</a> below. Additional constraints defined for the whole
 125  table. You will probably need to prefix this with a comma. </li>
 126  </ul>
 127  <p>Database specific table options can be defined also using the name
 128  of the database type as the array key. In the following example, <em>create
 129  the table as ISAM with MySQL, and store the table in the "users"
 130  tablespace if using Oracle</em>. And because we specified REPLACE, drop
 131  the table first.</p>
 132  <pre>  $taboptarray = array('mysql' =&gt; 'TYPE=ISAM', 'oci8' =&gt; 'tablespace users', 'REPLACE');</pre>
 133  <p><a name=foreignkey></a>You can also define foreign key constraints. The following is syntax
 134  for postgresql:
 135  </p>
 136  <pre>  $taboptarray = array('constraints' =&gt; ', FOREIGN KEY (col1) REFERENCES reftable (refcol)');</pre>
 137  <h4>function DropTableSQL($tabname)</h4>
 138  <p>Returns the SQL to drop the specified table.</p>
 139  <h4>function ChangeTableSQL($tabname, $flds)</h4>
 140  <p>Checks to see if table exists, if table does not exist, behaves like
 141  CreateTableSQL. If table exists, generates appropriate ALTER TABLE
 142  MODIFY COLUMN commands if field already exists, or ALTER TABLE ADD
 143  $column if field does not exist.</p>
 144  <p>The class must be connected to the database for ChangeTableSQL to
 145  detect the existence of the table. Idea and code contributed by Florian
 146  Buzin.</p>
 147  <h4>function RenameTableSQL($tabname,$newname)</h4>
 148  <p>Rename a table.  Returns the an array of strings, which is the SQL required to rename a table. Since ADOdb 4.53. Contributed by Ralf Becker.</p>
 149  <h4> function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='')</h4>
 150  <p>Rename a table field. Returns the an array of strings, which is the SQL required to rename a column. The optional $flds is a complete column-defintion-string like for AddColumnSQL, only used by mysql at the moment. Since ADOdb 4.53. Contributed by Ralf Becker.</p>
 151  <h4>function CreateIndexSQL($idxname, $tabname, $flds,
 152  $idxoptarray=false)</h4>
 153  <pre>  RETURNS:      an array of strings, the sql to be executed, or false<br>  $idxname:     name of index<br>  $tabname:     name of table<br>  $flds:        list of fields as a comma delimited string or an array of strings<br>  $idxoptarray: array of index creation options<br></pre>
 154  <p>$idxoptarray is similar to $taboptarray in that index specific
 155  information can be embedded in the array. Other options include:</p>
 156  <pre>  CLUSTERED     Create clustered index (only mssql)<br>  BITMAP        Create bitmap index (only oci8)<br>  UNIQUE        Make unique index<br>  FULLTEXT      Make fulltext index (only mysql)<br>  HASH          Create hash index (only postgres)<br>  DROP          Drop legacy index<br></pre>
 157  <h4>function DropIndexSQL ($idxname, $tabname = NULL)</h4>
 158  <p>Returns the SQL to drop the specified index.</p>
 159  <h4>function AddColumnSQL($tabname, $flds)</h4>
 160  <p>Add one or more columns. Not guaranteed to work under all situations.</p>
 161  <h4>function AlterColumnSQL($tabname, $flds)</h4>
 162  <p>Warning, not all databases support this feature.</p>
 163  <h4>function DropColumnSQL($tabname, $flds)</h4>
 164  <p>Drop 1 or more columns.</p>
 165  <h4>function SetSchema($schema)</h4>
 166  <p>Set the schema.</p>
 167  <h4>function &amp;MetaTables()</h4>
 168  <h4>function &amp;MetaColumns($tab, $upper=true, $schema=false)</h4>
 169  <h4>function &amp;MetaPrimaryKeys($tab,$owner=false,$intkey=false)</h4>
 170  <h4>function &amp;MetaIndexes($table, $primary = false, $owner = false)</h4>
 171  <p>These functions are wrappers for the corresponding functions in the
 172  connection object. However, the table names will be autoquoted by the
 173  TableName function (see below) before being passed to the connection
 174  object.</p>
 175  <h4>function NameQuote($name = NULL)</h4>
 176  <p>If the provided name is quoted with backquotes (`) or contains
 177  special characters, returns the name quoted with the appropriate quote
 178  character, otherwise the name is returned unchanged.</p>
 179  <h4>function TableName($name)</h4>
 180  <p>The same as NameQuote, but will prepend the current schema if
 181  specified</p>
 182  <h4>function MetaType($t,$len=-1,$fieldobj=false)</h4>
 183  <h4>function ActualType($meta)</h4>
 184  <p>Convert between database-independent 'Meta' and database-specific
 185  'Actual' type codes.</p>
 186  <h4>function ExecuteSQLArray($sqlarray, $contOnError = true)</h4>
 187  <pre>  RETURNS:      0 if failed, 1 if executed all but with errors, 2 if executed successfully<br>  $sqlarray:    an array of strings with sql code (no semicolon at the end of string)<br>  $contOnError: if true, then continue executing even if error occurs<br></pre>
 188  <p>Executes an array of SQL strings returned by CreateTableSQL or
 189  CreateIndexSQL.</p>
 190  <hr />
 191  <a name="xmlschema"></a>
 192  <h2>ADOdb XML Schema (AXMLS)</h2>
 193  <p>This is a class contributed by Richard Tango-Lowy and Dan Cech that
 194  allows the user to quickly
 195  and easily build a database using the excellent ADODB database library
 196  and a simple XML formatted file.
 197  You can <a href="http://sourceforge.net/projects/adodb-xmlschema/">download
 198  the latest version of AXMLS here</a>.</p>
 199  <h3>Quick Start</h3>
 200  <p>Adodb-xmlschema, or AXMLS, is a set of classes that allow the user
 201  to quickly and easily build or upgrade a database on almost any RDBMS
 202  using the excellent ADOdb database library and a simple XML formatted
 203  schema file. Our goal is to give developers a tool that's simple to
 204  use, but that will allow them to create a single file that can build,
 205  upgrade, and manipulate databases on most RDBMS platforms.</p>
 206  <span style="font-weight: bold;"> Installing axmls</span>
 207  <p>The easiest way to install AXMLS to download and install any recent
 208  version of the ADOdb database abstraction library. To install AXMLS
 209  manually, simply copy the adodb-xmlschema.inc.php file and the xsl
 210  directory into your adodb directory.</p>
 211  <span style="font-weight: bold;"> Using AXMLS in Your Application</span>
 212  <p>There are two steps involved in using AXMLS in your application:
 213  first, you must create a schema, or XML representation of your
 214  database, and second, you must create the PHP code that will parse and
 215  execute the schema.</p>
 216  <p>Let's begin with a schema that describes a typical, if simplistic
 217  user management table for an application.</p>
 218  <pre class="listing"><pre>&lt;?xml version="1.0"?&gt;<br>&lt;schema version="0.2"&gt;<br><br>  &lt;table name="users"&gt;<br>    &lt;desc&gt;A typical users table for our application.&lt;/desc&gt;<br>    &lt;field name="userId" type="I"&gt;<br>      &lt;descr&gt;A unique ID assigned to each user.&lt;/descr&gt;<br><br>      &lt;KEY/&gt;<br>      &lt;AUTOINCREMENT/&gt;<br>    &lt;/field&gt;<br>    <br>    &lt;field name="userName" type="C" size="16"&gt;&lt;NOTNULL/&gt;&lt;/field&gt;<br><br>    <br>    &lt;index name="userName"&gt;<br>      &lt;descr&gt;Put a unique index on the user name&lt;/descr&gt;<br>      &lt;col&gt;userName&lt;/col&gt;<br>      &lt;UNIQUE/&gt;<br><br>    &lt;/index&gt;<br>  &lt;/table&gt;<br>  <br>  &lt;sql&gt;<br>    &lt;descr&gt;Insert some data into the users table.&lt;/descr&gt;<br>    &lt;query&gt;insert into users (userName) values ( 'admin' )&lt;/query&gt;<br><br>    &lt;query&gt;insert into users (userName) values ( 'Joe' )&lt;/query&gt;<br>  &lt;/sql&gt;<br>&lt;/schema&gt;            <br></pre></pre>
 219  <p>Let's take a detailed look at this schema.</p>
 220  <p>The opening &lt;?xml version="1.0"?&gt; tag is required by XML. The
 221  &lt;schema&gt; tag tells the parser that the enclosed markup defines an
 222  XML schema. The version="0.2" attribute sets <em>the version of the
 223  AXMLS DTD used by the XML schema.</em> </p>
 224  <p>All versions of AXMLS prior to version 1.0 have a schema version of
 225  "0.1". The current schema version is "0.2".</p>
 226  <pre class="listing"><pre>&lt;?xml version="1.0"?&gt;<br>&lt;schema version="0.2"&gt;<br>  ...<br>&lt;/schema&gt;<br></pre></pre>
 227  <p>Next we define one or more tables. A table consists of a fields (and
 228  other objects) enclosed by &lt;table&gt; tags. The name="" attribute
 229  specifies the name of the table that will be created in the database.</p>
 230  <pre class="listing"><pre>&lt;table name="users"&gt;<br><br>    &lt;desc&gt;A typical users table for our application.&lt;/desc&gt;<br>    &lt;field name="userId" type="I"&gt;<br><br>      &lt;descr&gt;A unique ID assigned to each user.&lt;/descr&gt;<br>      &lt;KEY/&gt;<br>      &lt;AUTOINCREMENT/&gt;<br>    &lt;/field&gt;<br>    <br>    &lt;field name="userName" type="C" size="16"&gt;&lt;NOTNULL/&gt;&lt;/field&gt;<br><br>    <br>&lt;/table&gt;<br></pre></pre>
 231  <p>This table is called "users" and has a description and two fields.
 232  The description is optional, and is currently only for your own
 233  information; it is not applied to the database.</p>
 234  <p>The first &lt;field&gt; tag will create a field named "userId" of
 235  type "I", or integer. (See the ADOdb Data Dictionary documentation for
 236  a list of valid types.) This &lt;field&gt; tag encloses two special
 237  field options: &lt;KEY/&gt;, which specifies this field as a primary
 238  key, and &lt;AUTOINCREMENT/&gt;, which specifies that the database
 239  engine should automatically fill this field with the next available
 240  value when a new row is inserted.</p>
 241  <p>The second &lt;field&gt; tag will create a field named "userName" of
 242  type "C", or character, and of length 16 characters. The
 243  &lt;NOTNULL/&gt; option specifies that this field does not allow NULLs.</p>
 244  <p>There are two ways to add indexes to a table. The simplest is to
 245  mark a field with the &lt;KEY/&gt; option as described above; a primary
 246  key is a unique index. The second and more powerful method uses the
 247  &lt;index&gt; tags.</p>
 248  <pre class="listing"><pre>&lt;table name="users"&gt;<br>  ...<br>    <br>  &lt;index name="userName"&gt;<br>    &lt;descr&gt;Put a unique index on the user name&lt;/descr&gt;<br>    &lt;col&gt;userName&lt;/col&gt;<br><br>    &lt;UNIQUE/&gt;<br>  &lt;/index&gt;<br>    <br>&lt;/table&gt;<br></pre></pre>
 249  <p>The &lt;index&gt; tag specifies that an index should be created on
 250  the enclosing table. The name="" attribute provides the name of the
 251  index that will be created in the database. The description, as above,
 252  is for your information only. The &lt;col&gt; tags list each column
 253  that will be included in the index. Finally, the &lt;UNIQUE/&gt; tag
 254  specifies that this will be created as a unique index.</p>
 255  <p>Finally, AXMLS allows you to include arbitrary SQL that will be
 256  applied to the database when the schema is executed.</p>
 257  <pre class="listing"><pre>&lt;sql&gt;<br>  &lt;descr&gt;Insert some data into the users table.&lt;/descr&gt;<br>  &lt;query&gt;insert into users (userName) values ( 'admin' )&lt;/query&gt;<br><br>  &lt;query&gt;insert into users (userName) values ( 'Joe' )&lt;/query&gt;<br>&lt;/sql&gt;<br></pre></pre>
 258  <p>The &lt;sql&gt; tag encloses any number of SQL queries that you
 259  define for your own use.</p>
 260  <p>Now that we've defined an XML schema, you need to know how to apply
 261  it to your database. Here's a simple PHP script that shows how to load
 262  the schema.</p>
 263  <pre class="listing"><pre>&lt;?PHP<br>/* You must tell the script where to find the ADOdb and<br> * the AXMLS libraries.<br> */
 264  require( "path_to_adodb/adodb.inc.php");
 265  require( "path_to_adodb/adodb-xmlschema.inc.php" ); # or adodb-xmlschema03.inc.php
 266  
 267  /* Configuration information. Define the schema filename,<br> * RDBMS platform (see the ADODB documentation for valid<br> * platform names), and database connection information here.<br> */<br>$schemaFile = 'example.xml';<br>$platform = 'mysql';<br>$dbHost = 'localhost';<br>$dbName = 'database';<br>$dbUser = 'username';<br>$dbPassword = 'password';<br><br>/* Start by creating a normal ADODB connection.<br> */<br>$db = ADONewConnection( $platform );<br>$db-&gt;Connect( $dbHost, $dbUser, $dbPassword, $dbName );<br><br>/* Use the database connection to create a new adoSchema object.<br> */<br>$schema = new adoSchema( $db );<br><br>/* Call ParseSchema() to build SQL from the XML schema file.<br> * Then call ExecuteSchema() to apply the resulting SQL to <br> * the database.<br> */<br>$sql = $schema-&gt;ParseSchema( $schemaFile );<br>$result = $schema-&gt;ExecuteSchema();<br>?&gt;<br></pre></pre>
 268  <p>Let's look at each part of the example in turn. After you manually
 269  create the database, there are three steps required to load (or
 270  upgrade) your schema.</p>
 271  <p>First, create a normal ADOdb connection. The variables and values
 272  here should be those required to connect to your database.</p>
 273  <pre class="listing"><pre>$db = ADONewConnection( 'mysql' );<br>$db-&gt;Connect( 'host', 'user', 'password', 'database' );<br></pre></pre>
 274  <p>Second, create the adoSchema object that load and manipulate your
 275  schema. You must pass an ADOdb database connection object in order to
 276  create the adoSchema object.</p>
 277  <pre class="listing">$schema = new adoSchema( $db );<br></pre>
 278  <p>Third, call ParseSchema() to parse the schema and then
 279  ExecuteSchema() to apply it to the database. You must pass
 280  ParseSchema() the path and filename of your schema file.</p>
 281  <pre class="listing">$schema-&gt;ParseSchema( $schemaFile ); <br>$schema-&gt;ExecuteSchema();</pre>
 282  <p>Execute the above code and then log into your database. If you've
 283  done all this right, you should see your tables, indexes, and SQL.</p>
 284  <p>You can find the source files for this tutorial in the examples
 285  directory as tutorial_shema.xml and tutorial.php. See the class
 286  documentation for a more detailed description of the adoSchema methods,
 287  including methods and schema elements that are not described in this
 288  tutorial.</p>
 289  <h3>XML Schema Version 3</h3>
 290  <p>In March 2006, we added adodb-xmlschema03.inc.php to the release, which supports version 3 of XML Schema. 
 291  The adodb-xmlschema.inc.php remains the same as previous releases, and supports version 2 of XML Schema. 
 292  Version 3 provides some enhancements:
 293  
 294  <ul>
 295       <li> Support for updating table data during an upgrade.
 296       <li> Support for platform-specific table options and platform negation.
 297       <li> Support for unsigned fields.
 298       <li> Fixed opt and constraint support
 299       <li> Many other fixes such as OPT tag, which allows you to set optional platform settings:
 300  </ul>
 301  
 302  <p>Example usage:
 303  <pre>&lt;?xml version="1.0"?>
 304  <b>&lt;schema version="0.3"></b>
 305   &lt;table name="ats_kb">
 306    &lt;descr>ATS KnowledgeBase&lt;/descr>
 307    &lt;opt platform="mysql">TYPE=INNODB&lt;/opt>
 308    &lt;field name="recid" type="I"/>
 309    &lt;field name="organization_code" type="I4"/> 
 310    &lt;field name="sub_code" type="C" size="20"/>
 311    etc...
 312  </pre>
 313  <p>To use it, change your code to include adodb-xmlschema03.inc.php.
 314  
 315  <h3>Upgrading</h3>
 316  <p>
 317  If your schema version is older, than XSLT is used to transform the
 318  schema to the newest version. This means that if you are using an older
 319  XML schema format, you need to have the XSLT extension installed.
 320  If you do not want to require your users to have the XSLT extension
 321  installed, make sure you modify your XML schema to conform to the
 322  latest version.
 323  <hr />
 324  <address>If you have any questions or comments, please email them to
 325  Richard at richtl#arscognita.com.
 326  </address>
 327  </body>
 328  </html>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics