Manuel Pear
Create Database
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();
- ?>
Remonter 
