----------------------------------------
$dsn = array ( 'phptype' => 'mysql',
               'hostspec' => 'localhost:3306',
               'username' => 'user',
               'password' => 'pass',
               'database' => 'mdb2test'
              );
----------------------------------------
phptype://nazwa-uytkownika:haso@specyfikacja-hosta/baza-danych
----------------------------------------
$dsn = 'mysql://user:pass@localhost:3306/mdb2test';
----------------------------------------
$mdb2 =& MDB2::connect($dsn);
$mdb2 =& MDB2::factory($dsn);
$mdb2 =& MDB2::singleton($dsn);
----------------------------------------
$dsn = 'mysql://root@localhost/mdb2test';
$mdb2_first =& MDB2::singleton($dsn);
$mdb2_first->setDatabase('inna_db');
$mdb2_second =& MDB2::singleton($dsn);
----------------------------------------
$options = array ( 'persistent' => true,
                   'ssl' => true,
                  );
$mdb2 =& $MDB2::factory($dsn, $options);
----------------------------------------
$mdb2->setOption('portability', MDB2_PORTABILITY_NONE);
----------------------------------------
$options = array ( 'persistent' => true
                 );
$mdb2 =& MDB2::factory($dsn, $options);
----------------------------------------
$mdb2->setOption('persistent', true);
----------------------------------------
MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_LOWERCASE
----------------------------------------
MDB2_PORTABILITY_RTRIM | MDB2_PORTABILITY_EMPTY_TO_NULL
----------------------------------------
$mdb2->setFetchMode(MDB2_FETCHMODE_ORDERED);
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
$mdb2->setFetchMode(MDB2_FETCHMODE_OBJECT);
----------------------------------------
echo $result[0]; // uporzdkowana lub indeksowana tablica, domylnie w MDB2
echo $result['name']; // tablica asocjacyjna
echo $result->name; // obiekt
----------------------------------------
$mdb2->disconnect();
----------------------------------------
<?php
require_once 'MDB2.php';
// przygotowania
$dsn = 'mysql://root:secret@localhost/mdb2test';
$options = array ('persistent' => true);
$mdb2 =& MDB2::factory($dsn, $options);
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
// wykonujemy zapytanie
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
// wywietlamy imiona
while ($row = $result->fetchRow())
{
echo $row['name'], '<br />';
}
// zwalniamy wykorzystywane zasoby
$result->free();
// wyczamy zapytania
$mdb2->setOption('disable_query', true);
// usuwamy trzeci rekord
$id = 3;
$sql = 'DELETE FROM people WHERE id=%d';
$sql = sprintf($sql, $mdb2->quote($id, 'integer'));
echo '<hr />Zmienione wiersze: ';
echo $mdb2->exec($sql);
// zamykamy poczenie
$mdb2->disconnect();
?>
----------------------------------------
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
----------------------------------------
while ($row = $result->fetchRow())
{
   echo $row['name'], '<br />';
}
----------------------------------------
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
echo $result->numCols(); // wywietla 4
echo $result->numRows(); // wywietla 3
----------------------------------------
// instrukcja SQL
$sql = 'SELECT * FROM people';
// jeden ze sposobw pobierania wszystkich danych
$result = $mdb2->query($sql);
$data = $result->fetchAll();
$result->free(); // not required, but a good habit
// krtszy sposb
$data = $mdb2->queryAll($sql);
----------------------------------------
Array ( [0] => Array ( [id] => 1
                       [name] => Eddie
                       [family] => Vedder
                       [birth_date] => 1964-12-23
                     )
        [1] => Array ( [id] => 2
                       [name] => Mike
                       [family] => McCready
                       [birth_date] => 1966-04-05
                      )
...
)
----------------------------------------
$sql = 'SELECT * FROM people WHERE id=?';
$mdb2->loadModule('Extended');
$data = $mdb2->getRow($sql, null, array(1));
----------------------------------------
$sql = 'SELECT * FROM people WHERE id=:the_id';
$mdb2->loadModule('Extended');
$data = $mdb2->getRow( $sql,
                       null,
                       array('the_id' => 1)
                      );
----------------------------------------
$mdb2->extended->getAll($sql);
----------------------------------------
$mdb2->getAll($sql);
----------------------------------------
$sql = 'SELECT id, name FROM people';
$mdb2->loadModule('Extended');
$data = $mdb2->getAll($sql);
----------------------------------------
Array ( [0] => Array ( [id] => 1
                       [name] => Eddie
                     )
        [1] => Array ( [id] => 2
                       [name] => Mike
                     )
...
)
----------------------------------------
Array ( [1] => Eddie
        [2] => Mike
        [3] => Stone
       )
----------------------------------------
$sql = 'SELECT id, name, family FROM people';
$mdb2->loadModule('Extended');
$data = $mdb2->getAssoc($sql);
----------------------------------------
Array ( [1] => Array ( [name] => Eddie
                       [family] => Vedder
                     )
      ...
      )
----------------------------------------
$valid_types = array ( 'text' => '',
                       'boolean' => true,
                       'integer' => 0,
                       'decimal' => 0.0,
                       'float' => 0.0,
                       'timestamp' => '1970-01-01 00:00:00',
                       'time' => '00:00:00',
                       'date' => '1970-01-01',
                       'clob' => '',
                       'blob' => '',
                     )
----------------------------------------
http://cvs.php.net/viewcvs.cgi/pear/MDB2/docs/datatypes.html?view=co
----------------------------------------
$sql = 'SELECT * FROM people';
$types = array();
$result = $mdb2->query($sql, $types);
$row = $result->fetchRow();
var_dump($row);
----------------------------------------
array(2)
{
    ["id"] => string(1) "1"
    ["name"]=> string(5) "Eddie"
...
}
----------------------------------------
$types = array('integer', 'text');
----------------------------------------
array(2)
{
    ["id"]=> int(1)
    ["name"]=> string(5) "Eddie"
...
}
----------------------------------------
$types = array( 'id' => 'integer',
                'name' => 'text'
               );
$types = array('name'=>'text');
$types = array('integer');
----------------------------------------
// wykonujemy zapytanie
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
// pobieramy pierwszy wiersz bez konwertowania typw
$row = $result->fetchRow();
var_dump($row['id']);
// wynik bdzie nastpujcy: string(1) "1"

// okrelamy typy
$types = array('integer');
$result->setResultTypes($types);
// wszystkie nastpne pobrania bd konwertowa
// pierwsz kolumn na liczb cakowit
$row = $result->fetchRow();
var_dump($row['id']);
// wynik bdzie nastpujcy: int(2)
----------------------------------------
$sql = 'UPDATE %s SET %s=%s WHERE id=%d';
$sql = sprintf( $sql,
                $mdb2->quoteIdentifier('people'),
                $mdb2->quoteIdentifier('name'),
                $mdb2->quote('Eddie'), // domniemany typ danych
                $mdb2->quote(1, 'integer') // wyranie okrelony typ danych
               );
----------------------------------------
UPDATE `people` SET `name`='Eddie' WHERE id=1
----------------------------------------
UPDATE "people" SET "name"='Eddie' WHERE id=1
----------------------------------------
foreach ($result as $row)
{
   var_dump($row);
}
----------------------------------------
while ($row = $result->fetchRow())
{
   var_dump($row);
}
----------------------------------------
MDB2::loadFile('Iterator');
----------------------------------------
$query = 'SELECT * FROM people';
$result = $mdb2->query($query, null, true, 'MDB2_BufferedIterator');
----------------------------------------
$mdb2->setOption('debug', 1);
----------------------------------------
$mdb2->getDebugOutput();
----------------------------------------
$mdb2->setOption('debug', 1);
$mdb2->setOption('log_line_break', "\n\t");

$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
$sql = 'SELECT * FROM people WHERE id = 1';
$result = $mdb2->query($sql);
$sql = 'SELECT name FROM people';
$result = $mdb2->query($sql);

$debug_array = explode("\n\t", trim($mdb2->getDebugOutput()));

echo '<ul><li>';
echo implode('</li><li>', $debug_array);
echo '</li></ul>';
----------------------------------------
$my_new_id = $mdb2->nextId('people');
----------------------------------------
$mdb2->setOption('seqcol_name', 'id');
----------------------------------------
SELECT * FROM people LIMIT 0, 2;
----------------------------------------
$sql = 'SELECT * FROM people';
$mdb2->setLimit(2);
$result = $mdb2->query($sql);
----------------------------------------
$mdb2->setLimit(2, 1);
----------------------------------------
$mdb2->loadModule('Extended');
$sql = 'SELECT * FROM people';
$result = $mdb2->limitQuery($sql, null, 2, 1);
----------------------------------------
$fields=array ( 'id' => array ( 'value' => 6,
                                'key' => true
                               ),
                'name' => array ('value' => 'Stoyan'),
                'family' => array ('value' => 'Stefanov'),
                'birth_date' => array ('value' => '1975-06-20')
              );
$mdb2->replace('people', $fields);
----------------------------------------
// acuch zapytania subselektu 
$sql_ss = 'SELECT id FROM people WHERE id = 1 OR id = 2';
// gwne zapytanie
$sql = 'SELECT * FROM people WHERE id IN (%s)';
// przywoujemy subSelect()
$subselect = $mdb2->subSelect($sql_ss);
// aktualizujemy i wywietlamy gwne zapytanie
echo $sql = sprintf($sql, $subselect);
// wykonujemy zapytanie
$data = $mdb2->queryAll($sql);
----------------------------------------
SELECT * FROM people WHERE id IN
(SELECT id FROM people WHERE id = 1 OR id = 2)
----------------------------------------
SELECT * FROM people WHERE id IN (1, 2)
----------------------------------------
$sql = 'INSERT INTO people VALUES (?, ?, ?, ?)';
----------------------------------------
$sql = 'INSERT INTO people VALUES
        (:id, :first_name, :last_name, :bdate)';
----------------------------------------
$statement = $mdb2->prepare($sql);
----------------------------------------
$data = array(
              $mdb2->nextId('people'), 'Matt', 'Cameron', '1962-11-28'
              );
----------------------------------------
$statement->execute($data);
----------------------------------------
$statement->free();
----------------------------------------
$data = array( 'first_name' => 'Jeff',
               'last_name' => 'Ament',
               'id' => $mdb2->nextId('people'),
               'bdate' => '1963-03-10'
             );
----------------------------------------
// przygotowujemy instrukcj
$sql = 'INSERT INTO people VALUES
        (:id, :first_name, :last_name, :bdate)';
$statement = $mdb2->prepare($sql);
// ustalamy dane
$id = $mdb2->nextId('people');
$first_name = 'Kirk';
$last_name = 'Hammett';
$bdate = '1962-11-18';
// wiemy dane
$statement->bindParam('id', $id);
$statement->bindParam('first_name', $first_name);
$statement->bindParam('last_name', $last_name);
$statement->bindParam('bdate', $bdate);
// wykonujemy zapytanie i zwalniamy dane
$statement->execute();
$statement->free();
----------------------------------------
$array_to_bind = array('id' => $id,
                       'first_name' => $first_name,
                       'last_name' => $last_name,
                       'bdate' => $bdate
                      );
$statement->bindParamArray($array_to_bind);
----------------------------------------
$sql = 'INSERT INTO people VALUES (?, ?, ?, ?)';
$statement = $mdb2->prepare($sql);
$data = array(
   array($mdb2->nextId('people'), 'Janusz', 'Halski',
                                         '1969-06-06'),
   array($mdb2->nextId('people'), 'Lech', 'Uliasz',
                                      '1968-02-02')
             );
$mdb2->loadModule('Extended');
$mdb2->executeMultiple($statement, $data);
$statement->free();
----------------------------------------
$mdb2->loadModule('Extended');
$table = 'people';
$fields = array('id', 'name', 'family', 'birth_date');
$statement = $mdb2->autoPrepare($table, $fields,
                                               MDB2_AUTOQUERY_INSERT);
----------------------------------------
INSERT INTO people (id, name, family, birth_date) VALUES (?, ?, ?, ?)
----------------------------------------
$mdb2->loadModule('Extended');
$table = 'people';
$fields = array('name', 'family', 'birth_date');
$where = 'id = ?';
$statement = $mdb2->autoPrepare($table, $fields,
                                       MDB2_AUTOQUERY_UPDATE, $where);
----------------------------------------
UPDATE people SET name = ?, family = ?, birth_date = ? WHERE id = ?
----------------------------------------
$mdb2->loadModule('Extended');
$sql = $mdb2->buildManipSQL(
    'people',
     false,
     MDB2_AUTOQUERY_DELETE,
     'family like "s%"');
echo $mdb2->exec($sql);
----------------------------------------
$mdb2->loadModule('Extended');
$table = 'people';
$fields = array ( 'id' => $mdb2->nextId('people'),
                  'name' => 'Ryszard',
                  'family' => 'Burton',
                  'birth_date' => '1962-02-10'
                );
$result = $mdb2->autoExecute($table, $fields, MDB2_AUTOQUERY_INSERT);
----------------------------------------
if ($mdb2->supports('transactions'))
{
    $mdb2->beginTransaction();
}
$result = $mdb2->exec('DELETE FROM people WHERE id = 33');
if (PEAR::isError($result))
{
    if ($mdb2->inTransaction())
    {
        $mdb2->rollback();
    }
}
$result = $mdb2->exec('DELETE FROM people WHERE id =
invalid something');
if (PEAR::isError($result))
{
    if ($mdb2->inTransaction())
    {
        $mdb2->rollback();
    }
}
elseif ($mdb2->inTransaction())
{
     $mdb2->commit();
}
----------------------------------------
$mdb2->loadModule('Extended');
----------------------------------------
$mdb2->extended->getAssoc($sql);
----------------------------------------
$mdb2->getAssoc($sql);
----------------------------------------
$mdb2->exGetAssoc($sql);
----------------------------------------
$mdb2->loadModule('Extended', 'mine');
$mdb2->mine->getAssoc($sql);
----------------------------------------
$mdb2->loadModule('Manager');
$mdb2->createDatabase('test_db');
----------------------------------------
$definition = array ( 'id' => array ( 'type' => 'integer',
                                      'unsigned' => 1,
                                      'notnull' => 1,
                                      'default' => 0,
                                    ),
                      'name' => array ( 'type' => 'text',
                                        'length' => 255
                                      ),
                      'family' => array ( 'type' => 'text',
                                          'length' => 255
                                        ),
                      'birth_date' => array ( 'type' => 'date'
                                            )
                    );
$mdb2->createTable('people', $definition);
----------------------------------------
$definition = array(
    'change' => array(
        'name' => array(
            'definition' => array(
                'length' => 100,
                'type' => 'text',
                                  )
                           ),
                        )
           );
$mdb2->alterTable('people', $definition, false);
----------------------------------------
$definition = array ( 'primary' => true,
                      'fields' => array ( 'id' => array())
                     );
$mdb2->createConstraint('people', 'myprimekey', $definition);
----------------------------------------
$definition = array('unique' => true,
                    'fields' => array('name' => array(),
                                      'family' => array(),
                                      )
                    );
$mdb2->createConstraint('people', 'unique_people',
                                     $definition);
----------------------------------------
$mdb2->dropConstraint('people', 'unique_people');
----------------------------------------
$definition = array('fields' => array('birth_date' => array(),) );
$mdb2->createIndex('people', 'dates', $definition);
----------------------------------------
$mdb2->setOption('idxname_format', '%s'); // bez przyrostka
----------------------------------------
$mdb2->loadModule('Function');
echo $mdb2->now();
----------------------------------------
$mdb2->loadModule('Function');
$sql = 'SELECT %s FROM people';
$first_initial = $mdb2->substring('name', 1, 1);
$dot = $mdb2->quote('.');
$all = $mdb2->concat($first_initial, $dot, 'family');
$sql = sprintf($sql, $all);
$data = $mdb2->queryCol($sql);

echo $sql;
print_r($data);
----------------------------------------
Array (
   [0] => E.Vedder
   [1] => M.McCready
   [2] => S.Gossard
...
      )
----------------------------------------
SELECT CONCAT(SUBSTRING(name FROM 1 FOR 1), '.', family) FROM people
----------------------------------------
SELECT (SUBSTR(name, 1, 1) || '.' || family) FROM people
----------------------------------------
$mdb2->loadModule('Reverse');
$data = $mdb2->tableInfo('people');
----------------------------------------
Array( [0] => Array ( [table] => people
                      [name] => id
                      [type] => int
                      [length] => 11
                      [flags] => not_null primary_key
                      [mdb2type] => integer
                     )
       [1] => Array ( [table] => people
                      [name] => name
                      [type] => char
                      [length] => 100
                      [flags] =>
                      [mdb2type] => text
                     )
...
 )
----------------------------------------
$mdb2->loadModule('Reverse');

$sql = 'SELECT phones.id, people.name, phones.phone ';
$sql.= ' FROM people ';
$sql.= ' LEFT JOIN phones ';
$sql.= ' ON people.id = phones.person_id ';

$result = $mdb2->query($sql);
$data = $mdb2->tableInfo($result);
----------------------------------------
Array (
[0] => Array ( [table] => phones
               [name] => id
               [type] => int
               [length] => 11
               [flags] => primary_key
               [mdb2type] => integer
             )
[1] => Array ( [table] => people
               [name] => name
               [type] => char
               [length] => 100
               [flags] =>
               [mdb2type] => text
             )
[2] => Array ( [table] => phones
               [name] => phone
               [type] => char
               [length] => 20
               [flags] =>
               [mdb2type] => text
             )
)
----------------------------------------
$mdb2->setOption('debug', 1);
----------------------------------------
$mdb2->getDebugOutput();
----------------------------------------
class Custom_Debug_Class
{
   // zliczamy, ile zapyta zostao wykonanych
   var $query_count = 0;
   // ktre zapytania i ich liczba
   var $queries = array();

   // ta metoda przywoywana jest przy kadym zapytaniu
   function collectInfo(&$db, $scope, $message, $is_manip =
                                                      null)
   {
      $this->query_count++;
      @$this->queries[$message]++;
   }
   // wywietlamy dziennik
   function dumpInfo()
   {
      echo 'Cakowita liczba zapytan na tej stronie: ';
      echo $this->query_count;
      // sortujemy malejco
      arsort($this->queries);
      echo '<pre>';
      print_r($this->queries);
      echo '</pre>';
   }
}
----------------------------------------
$my_debug_handler = new Custom_Debug_Class();
$mdb2->setOption('debug', 1);
$mdb2->setOption('debug_handler', array($my_debug_handler,
                                          'collectInfo'));

$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
$sql = 'SELECT * FROM people WHERE id = 1';
$result = $mdb2->query($sql);
$my_debug_handler->dumpInfo();
----------------------------------------
Total queries in this page: 3
Array
(
  [SELECT * FROM people]=>2
  [SELECT * FROM people WHERE id = 1]=>1
)
----------------------------------------
register_shutdown_function(array($my_debug_handler,
                                       'dumpInfo'));
----------------------------------------
class My_Fetch_Class
{
   function __construct($row)
   {
      foreach ($row as $field => $data)
      {
         if ($field == 'id')
         {
            $data = (int)$data;
         }
         $this->{$field} = $data;
      }    
   }
}
----------------------------------------
$mdb2->setFetchMode(MDB2_FETCHMODE_OBJECT);
$mdb2->setOption('fetch_class', 'My_Fetch_Class');
----------------------------------------
$mdb2->setFetchMode(MDB2_FETCHMODE_OBJECT, 'My_Fetch_Class');
----------------------------------------
$sql = 'SELECT * FROM people WHERE id=1';
$data = $mdb2->queryRow($sql);
----------------------------------------
object(My_Fetch_Class)#3 (2)
{
   ["id"]=>
   int(1)
   ["name"]=>
   string(5) "Eddie"
   ...
}
----------------------------------------
class MyResult extends MDB2_Result_mysql
{
   function newResultMethod()
   {
       echo 'To jest MyResult::newResultMethod()';
       // $this->db to nasza bieca instancja MDB2 
       // na wypadek, gdybymy jej potrzebowali
   }
}
----------------------------------------
$mdb2->setOption('buffered_result_class', 'MyResult');
----------------------------------------
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql);
$result->newResultMethod();
----------------------------------------
$mdb2->setOption('result_buffering', false);
----------------------------------------
$mdb2->setOption('result_class', 'MyResult');
----------------------------------------
$mdb2->setOption('result_class', 'MyResult_%s');
----------------------------------------
class MyResult2 extends MDB2_BufferedResult_mysql
{
   function getAverageAge()
   {
      $current_row = $this->rowCount(); // gdzie jestemy
      $this->seek(); // przewijamy
      $total_ts = 0; // suma wszystkich znacznikw czasu dat urodzenia
      while ($row = $this->fetchRow(MDB2_FETCHMODE_ASSOC))
      {
         $total_ts += strtotime($row['birth_date']);
      }
      $avg_ts = $total_ts / $this->numRows();
                          // rednia warto znacznika czasu
      $age = date('Y') - date('Y', $avg_ts);
      if (date('md') < date('md', $avg_ts))
      {
         $age--; // to jeszcze nie data urodzenia
      }
      $this->seek($current_row); // wracamy tam, gdzie bylimy
      return $age;
   }
}
----------------------------------------
$sql = 'SELECT * FROM people';
// lub moe --> $sql = 'SELECT * FROM people WHERE name
// LIKE "J%"';
$result = $mdb2->query($sql, null, 'MyResult2');
echo $result->getAverageAge();
----------------------------------------
// adujemy iteratory MDB2 
MDB2::loadFile('Iterator');
// wasna klasa iteratora
class My_Iterator extends MDB2_BufferedIterator
{
   function foo()
   {
   echo 'bar';
   }
}
// wykonujemy zapytanie
$sql = 'SELECT * FROM people';
$result = $mdb2->query($sql, null, true, 'My_Iterator');
// przegldamy krok po korku zbir wynikw
foreach ($result as $row)
{
   var_dump($row);
}
// przywoujemy wasn metod
$result->foo();
----------------------------------------
class MDB2_Mymodule
{
   function sayHi()
   {
      echo "OK, witam!";
   }
}
----------------------------------------
$mdb2->loadModule('Mymodule');
$mdb2->sayHi();
----------------------------------------
class MDB2_Mymodule2 extends MDB2_Module_Common
{
   function getNumberOfRecords($table)
   {
       $mdb2 =& $this->getDBInstance();
       $sql = 'SELECT count(*) FROM '
       . $mdb2->quoteIdentifier($table);
       $count = $mdb2->queryOne($sql);
       return $count;
   }
}
----------------------------------------
$mdb2->loadModule('Mymodule2');
echo $mdb2->getNumberOfRecords('people');
----------------------------------------
require_once 'MDB2.php';
require_once 'MDB2/Schema.php';

$dsn = 'mysql://root@localhost/test_db';
$options = array('debug' => 0,);
$mdb2 =& MDB2::factory($dsn, $options);
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);

$schema =& MDB2_Schema::factory($mdb2);
----------------------------------------
$definition = $schema->getDefinitionFromDatabase();
$dump_options = array ( 'output_mode' => 'file',
                        'output' => 'test.xml'
                       );
$schema->dumpDatabase($definition, $dump_options,
                      MDB2_SCHEMA_DUMP_STRUCTURE);
----------------------------------------
Array
(
   [name] => test_db
   [create] => 1
   [overwrite] =>
   [tables] => Array
      (
         [people] => Array
            (
               [fields] => Array
                  (
                     [id] => Array ( [type] => integer
                                     [notnull] => 1
                                     [length] => 4
                                     [unsigned] => 1
                                     [default] => 0
                                   )
                                     [name] => Array ( [type] => text
                                     [notnull] =>
                                     [length] => 100
                                     [fixed] =>
                                     [default] =>
                                   )
                     ...
                  )
               [indexes] => Array (...)
      )
      )
         [sequences] => Array
      (
      )
)
----------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
   <name>test_db</name>
   <create>true</create>
   <overwrite>false</overwrite>

   <table>
      <name>people</name>
      <declaration>
      <field>
         <name>id</name>
         <type>integer</type>
         <unsigned>true</unsigned>
         <length>4</length>
         <notnull>true</notnull>
         <default>0</default>
      </field> 

      <field>
         <name>name</name>
         <type>text</type>
         <length>100</length>
         <notnull>false</notnull>
         <default></default>
      </field>

         ... 

      <index>
      ...
      </index>
      </declaration>
   </table>
</database>
----------------------------------------
function printXml($input)
{
   echo '<pre>';
   print_r(htmlentities($input));
   echo '</pre>';
}
----------------------------------------
$dump_options = array ( 'output' => 'printXml' );
----------------------------------------
$dsn2 = 'sqlite:///';
$schema2 =& MDB2_Schema::factory($dsn2);
$definition = $schema2->parseDatabaseDefinitionFile('test.xml');
$schema2->createDatabase($definition);
----------------------------------------
$schema2->createDatabase($schema->getDefinitionFromDatabase());
----------------------------------------

