最近在做数据库的导入导出工作,发现有一款类库叫:Danpu 挺好用的,就记录一下。项目地址:https://github.com/gocom/danpu。
一、安装
composer require rah/danpu
二、使用
1.导出
use Rah\Danpu\Dump;
use Rah\Danpu\Export;
try {
$dump = new Dump;
$dump
->file('/path/to/target/dump/file.sql')
->dsn('mysql:dbname=database;host=localhost')
->user('username')
->pass('password')
->tmp('/tmp');
new Export($dump);
} catch (\Exception $e) {
echo 'Export failed with message: ' . $e->getMessage();
}
2.导入
use Rah\Danpu\Dump;
use Rah\Danpu\Import;
try {
$dump = new Dump;
$dump
->file('/path/to/imported/file.sql')
->dsn('mysql:dbname=database;host=localhost')
->user('username')
->pass('password')
->tmp('/tmp');
new Import($dump);
} catch (\Exception $e) {
echo 'Import failed with message: ' . $e->getMessage();
}
网友评论