データベースの定義の取得 (Previous) (Next) データベースの作成

View this page in Last updated: Sun, 24 Aug 2008
English | French | German | Hungarian | Japanese | Spanish | Plain HTML

データベースのダンプ

データベースのダンプ -- データベースの MDB2 XML 形式でのダンプ

データベースのダンプ

dumpDatabase() を使用すると、 データベースの内容をスキーマファイルにコピーすることができます。 dumpDatabase() には、データベースの定義配列を次のように渡します。


<?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 {
    $dump_options = array(
      'output_mode' => 'file',
      'output' => 'schema.xml',
      'end_of_line' => "\n"
    );

    $definition $schema->getDefinitionFromDatabase();
    if (PEAR::isError($definition)) {
      $error $definition->getMessage();
    } else {
      $op $schema->dumpDatabase($definition$dump_optionsMDB2_SCHEMA_DUMP_ALL);

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

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

$schema->disconnect();
?>

最初のパラメータには、データベースの定義配列を指定します。 二番目のパラメータは、ファイルへの出力の際のオプションです。 三番目のオプションは、dumpDatabase() で何をダンプするのか (構造のみ、テーブル内のデータのみ、 あるいはその両方) を指定します。これは、定数 MDB2_SCHEMA_DUMP_STRUCTUREMDB2_SCHEMA_DUMP_CONTENT および MDB2_SCHEMA_DUMP_ALL のいずれかで指定します。

テキスト型のフィールドにデフォルト値を定義することのできないデータベースもあります。 そのようなデータベースを使用する場合は、text 型のフィールドを作成する際には $options['force_defaults']false に設定する必要があることに注意しましょう。 このオプションは、デフォルトで true となっています。

データベースの定義の取得 (Previous) (Next) データベースの作成

Download Documentation Last updated: Sun, 24 Aug 2008
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.