SQLDumper is a small library designed to easily create customized SQL dumps.
Via Composer
$ composer require y0lk/sqldumper
The concept is that you can select tables and set certain "dump parameters" for each table, made so you can chain a bunch of calls to quickly create a customized dump.
use Y0lk\SQLDumper\SQLDumper;
//Init the dumper with your DB info
$dumper = new SQLDumper('localhost', 'dbname', 'root', '');
//Set all tables to dump without data and without DROP statement
$dumper->allTables()
->withData(false)
->withDrop(false);
//Set table1 to dump with data
$dumper->table('table1')
->withData(true);
//Set table2 and table3 to dump without structure (data only), and table3 with where condition
$dumper->listTables([
'table2',
'table3'
])
->withStructure(false)
->table('table3')
->where('id=2 OR foo="bar"');
//This will group DROP statements and put them at the beginning of the dump
$dumper->groupDrops(true);
//This will group INSERT statements and put them at the end of the dump
$dumper->groupInserts(true);
$dumper->save('dump.sql');
When set to TRUE, this will group DROP statements and put them at the beginning of the dump
When set to TRUE, this will group INSERT statements and put them at the end of the dump
There are 3 basic methods to select tables. When a table or a list of tables are selected, they are returned as TableDumper objects on which you can set options for the dump.
Selects all the tables in the DB
Select by table's name (string) or a Table object
Select by a list of table names (string) or Table object
This is the list of methods available on each each TableDumper
Whether to dump the table CREATE structure
Whether to dump table data (INSERT statement)
Wheter to include the DROP statement (before CREATE)
WHERE query string as regular SQL
This the main dump function, outputs the dump to a stream.
Saves the dump to a file
The MIT License (MIT). Please see License File for more information.