美文网首页
MySQL数据库导入导出类库Danpu的使用

MySQL数据库导入导出类库Danpu的使用

作者: 周星星的学习笔记 | 来源:发表于2021-01-05 09:21 被阅读0次

最近在做数据库的导入导出工作,发现有一款类库叫: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();
}

相关文章

网友评论

      本文标题:MySQL数据库导入导出类库Danpu的使用

      本文链接:https://www.haomeiwen.com/subject/telioktx.html