Generic API for running console commands against a DB (previously hgg/dbbackup)
from within a PHP application., (*1)
, (*2)
Warning: The commands are constructed containing the password in order to run non-interactive. This can be considered to be insecure., (*3)
Operations include:, (*4)
- Create a database
- Drop a database
- Dump a table to a dump file
- Dump a database to a dump file
- Load a table from a dump file
Installation
Using Composer:, (*5)
{
"require": {
"hgg/dbcmd": "dev-master"
}
}
Download source and manually add to project:, (*6)
Supported Databases:
Pull Requests for additional database engines welcome!, (*7)
Usage
Dump entire database
use HGG\DbCmd\CmdBuilder\MySql;
use HGG\DbCmd\DbCmd;
try
{
$output = '';
$cmd = new DbCmd(new MySql());
$cmd->dumpDatabase('username', 'password', 'localhost', 'database',
'dumpFile', array(), &$output);
// log $output
}
catch (\Exception $e)
{
// deal with failure
}
Dump specific tables in a database
use HGG\DbCmd\CmdBuilder\MySql;
use HGG\DbCmd\DbCmd;
try
{
$output = '';
$cmd = new DbCmd(new MySql());
$cmd->dumpTables('username', 'password', 'localhost', 'database',
array('table1', 'table2'), 'dumpFile', array(), &$output);
// log $output
}
catch (\Exception $e)
{
// deal with failure
}
use HGG\DbCmd\CmdBuilder\MySql;
use HGG\DbCmd\DbCmd;
try
{
$output = '';
$cmd = new DbCmd(new MySql());
$cmd->load('username', 'password', 'localhost', 'database',
'dumpFile', array(), &$output);
// log $output
}
catch (\Exception $e)
{
// deal with failure
}