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:

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)) {

Dumping a database to MDB2 XML (Previous) Updating a database against a new schema (Next)
Last updated: Thu, 31 Jul 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

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.