PHP code example of spatie / db-dumper
1. Go to this page and download the library: Download spatie/db-dumper 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/ */
spatie / db-dumper example snippets
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\PostgreSql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\Sqlite::create()
->setDbName($pathToDatabaseFile)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MongoDb::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.gz');
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\PostgreSql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDumpBinaryPath('/custom/location')
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->setHost($host)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->skipAutoIncrement()
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->dontSkipAutoIncrement()
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDatabaseUrl($databaseUrl)
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->doNotUseColumnStatistics()
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->excludeTables(['table1', 'table2', 'table3'])
->dumpToFile('dump.sql');
Spatie\DbDumper\Databases\MySql::create()
->setDbName($databaseName)
->setUserName($userName)
->setPassword($password)
->excludeTables('table1, table2, table3')
->dumpToFile('dump.sql');
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->doNotCreateTables()
->getDumpCommand('dump.sql', 'credentials.txt');
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->doNotDumpData()
->getDumpCommand('dump.sql', 'credentials.txt');
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->addExtraOption('--xml')
->getDumpCommand('dump.sql', 'credentials.txt');
$dumpCommand = MySql::create()
->setUserName('username')
->setPassword('password')
->addExtraOption('--databases dbname')
->addExtraOption('--add-drop-database')
->getDumpCommand('dump.sql', 'credentials.txt');
$dumpCommand = MySql::create()
->setUserName('username')
->setPassword('password')
->addExtraOption('--all-databases')
->getDumpCommand('dump.sql', 'credentials.txt');
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->useCompressor(new GzipCompressor()) // or `new Bzip2Compressor()`
->dumpToFile('dump.sql.gz');
namespace Spatie\DbDumper\Compressors;
interface Compressor
{
public function useCommand(): string;
public function useExtension(): string;
}
namespace Spatie\DbDumper\Compressors;
class GzipCompressor implements Compressor
{
public function useCommand(): string
{
return 'gzip';
}
public function useExtension(): string
{
return 'gz';
}
}