Skip to content

Latest commit

 

History

History
101 lines (76 loc) · 1.87 KB

README.md

File metadata and controls

101 lines (76 loc) · 1.87 KB

Generic API for running console commands against a DB (previously hgg/dbbackup) from within a PHP application.

Build Status

Warning: The commands are constructed containing the password in order to run non-interactive. This can be considered to be insecure.

Operations include:

  • 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:

{
    "require": {
        "hgg/dbcmd": "dev-master"
    }
}

Download source and manually add to project:

  • Get the zip file here

Supported Databases:

  • MySql

Pull Requests for additional database engines welcome!

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
}

Restore form a dump file

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
}