Dump Database (Previous) (Next) Update Dabase

View this page in Last updated: Sun, 01 Jul 2007
English | French | German | Hungarian | Japanese | Spanish | Plain HTML

Create Database

Create Database -- Restoring a database from MDB2 XML

Create Database

When having a schema file, it is a breeze to create a database. Simply do the following:


<?php
require_once 'MDB2/Schema.php';

$options = array(
    'log_line_break' => '<br>',
    'idxname_format' => '%s',
    'debug' => true,
    'quote_identifier' => true,
    'force_defaults' => false,
    'portability' => false
);
$dsn = 'mysql://root:@localhost/MDB2Example';

$schema =& MDB2_Schema::factory($dsn, $options);

if (PEAR::isError($schema)) {
    $error = $schema->getMessage();
} else {
    // first run with queries disabled to make sure everything is allright
    $disable_query = true;

    $definition = $schema->parseDatabaseDefinitionFile('example.xml')
    if (PEAR::isError($definition)) {
      $error = $definition->getMessage();
    } else {
      $op = $schema->createDatabase($definition, array(), $disable_query);

      if (PEAR::isError($op)) {
        $error = $op->getMessage();
      }
    }
}

if (isset($error)) {
    var_dump($error);
}

$schema->disconnect();
?>

Dump Database (Previous) (Next) Update Dabase

Download Documentation Last updated: Sun, 01 Jul 2007
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.