PHP code example of ngyuki / dbdatool

1. Go to this page and download the library: Download ngyuki/dbdatool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ngyuki / dbdatool example snippets



return [
    'dsn' => 'mysql:host=localhost;port=3306;dbname=test;charset=utf8',
    'username' => 'oreore',
    'password' => 'himitu',
];


$host = getenv('MYSQL_HOST');
$port = getenv('MYSQL_PORT');
$dbname = getenv('MYSQL_DATABASE');
$username = getenv('MYSQL_USER');
$password = getenv('MYSQL_PASSWORD');

return [
    'dsn' => "mysql:host=$host;port=$port;dbname=$dbname;charset=utf8",
    'username' => $username,
    'password' => $password,
];
sh
php dbdatool.phar dump > schema.json
sh
php dbdatool.phar diff schema.json
json
{
    "extra": {
        "dbdatool-config": [
            "dbdatool.php",
            "dbdatool.php.dist"
        ]
    }
}
sh
# スキーマ定義ファイルの内容を、DSN 指定されたデータベースに反映
php dbdatool.phar apply schema.json mysql:host=192.0.2.123;port=3306;dbname=test;charset=utf8:user:password

# 空のデータソースを、コンフィグのデータベースに反映
# (すべてのテーブルが削除される)
php dbdatool.phar apply '!' @

# 別のコンフィグファイルのデータベースのスキーマ定義を、コンフィグのデータベースに反映
php dbdatool.phar apply staging.php @
sh
MYSQL_DATABASE=test php dbdatool.phar dump > schema.json
sh
php dbdatool.phar diff schema.json
php dbdatool.phar apply schema.json
sh
git pull -r
php dbdatool.phar diff schema.json
php dbdatool.phar apply schema.json