previousDump Database (Previous) (Next) Update Databasenext

View this page in Last updated: Tue, 02 Jun 2009
English | Brazilian Portuguese | Chinese | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Turkish

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();
?>
previousDump Database (Previous) (Next) Update Databasenext

Download Documentation Last updated: Tue, 02 Jun 2009
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
Note by: till
It would be nice if one of these examples actually showed an example.xml (or schema.xml) so people don't have to dump an existing database first to see them.