Manuel Pear

Dump Database

Dump Database -- Dumping a database to MDB2 XML

Dump Database

You can use dumpDatabase() to copy your database to a schema file. dumpDatabase() accepts a database definition array, for instance:

  1. <?php
  2. require_once 'MDB2/Schema.php';  
  3.  
  4. $options = array( 
  5.    'log_line_break' => '<br>', 
  6.    'idxname_format' => '%s', 
  7.    'debug' => true, 
  8.    'quote_identifier' => true, 
  9.    'force_defaults' => false, 
  10.    'portability' => false  
  11. );  
  12. $dsn = 'mysql://root:@localhost/MDB2Example';  
  13.  
  14. $schema =& MDB2_Schema::factory($dsn, $options);  
  15.  
  16. if (PEAR::isError($schema)) { 
  17.    $error = $schema->getMessage();  
  18. } else { 
  19.    $dump_options = array( 
  20.    'output_mode' => 'file', 
  21.    'output' => 'schema.xml', 
  22.    'end_of_line' => "\n" 
  23.    ); 
  24.  
  25.    $definition = $schema->getDefinitionFromDatabase(); 
  26.    if (PEAR::isError($definition)) { 
  27.    $error = $definition->getMessage(); 
  28.    } else { 
  29.    $op = $schema->dumpDatabase($definition, $dump_options, MDB2_SCHEMA_DUMP_ALL); 
  30.  
  31.    if (PEAR::isError($op)) { 
  32.       $error = $op->getMessage(); 
  33.    }  
  34. }  
  35. }  
  36.  
  37. if (isset($error)) { 
  38.    var_dump($error);  
  39. }  
  40.  
  41. $schema->disconnect();  
  42.  
  43. ?> 

The first parameter is just the database definition array. The second parameter is the options where we choose to output to a file. The third option tells dumpDatabase() what to be dumped - either the structure, the data in the tables, or both. This is defined using the constants MDB2_SCHEMA_DUMP_STRUCTURE, MDB2_SCHEMA_DUMP_CONTENT and MDB2_SCHEMA_DUMP_ALL.

Some databases don't accept a text field with a default value. Given that, notice that $options['force_defaults'] has to be set to false when you want to create a field with the type text, as it is true by default.


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique