Skip to content

remisauvat/mysqldump-php

Repository files navigation

MySQLDump - PHP

This is a php version of linux's mysqldump in terminal "$ mysqldump -u username -p...".

Build Status Scrutinizer Quality Score Latest Stable Version

Requirements

  • PHP 5 >= 5.3.0
  • PDO

Getting started

With autoloading/Composer:

<?php
    use Ifsnop\Mysqldump as IMysqldump;
    $dump = new IMysqldump\Mysqldump('database', 'username', 'password');
    $dump->start('storage/work/dump.sql');
?>

Without autoloading/Composer:

<?php
    include_once(dirname(__FILE__) . '/src/Ifsnop/Mysqldump/Mysqldump.php');
    $dump = new Ifsnop\Mysqldump\Mysqldump( 'database', 'username', 'password');
    $dump->start('storage/work/dump.sql');
?>

Constructor and default parameters

/**
 * Constructor of Mysqldump. Note that in the case of an SQLite database
 * connection, the filename must be in the $db parameter.
 *
 * @param string $db         Database name
 * @param string $user       SQL account username
 * @param string $pass       SQL account password
 * @param string $host       SQL server to connect to
 * @param string $type       SQL database type ('mysql', 'sqlite', ...)
 * @param array  $dumpSettings SQL database settings
 * @param array  $pdoSettings  PDO configured attributes
 *
 * @return null
 */
public function __construct(
    $db = '',
    $user = '',
    $pass = '',
    $host = 'localhost',
    $type = 'mysql',
    $dumpSettings = array(),
    $pdoSettings = array()
)

$dumpSettingsDefault = array(
    'include-tables' => array('table1', 'table2'),
    'exclude-tables' => array('table3', 'table4'),
    'compress' => 'GZIP',
    'no-data' => false,
    'add-drop-database' => false,
    'add-drop-table' => false,
    'single-transaction' => true,
    'lock-tables' => false,
    'add-locks' => true,
    'extended-insert' => true,
    'disable-foreign-keys-check' => false,
    'where' => '',
    'no-create-info' => false
);

$pdoSettingsDefaults = array(PDO::ATTR_PERSISTENT => true,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
);

// missing settings in constructor will be replaced by default options
$this->_pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
$this->_dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);

Dump Settings

PDO Settings

Composer

{
    "require": {
        "ifsnop/mysqldump-php": "dev-master",
    }
}

or

{
    "require": {
        "ifsnop/mysqldump-php": "1.0.*",
    }
}

Todo

  • Write unit tests.

Contributing

Format all code to PHP-FIG standards. http://www.php-fig.org/

License

This project is open-sourced software licensed under the MIT license

Credits

Originally based on James Elliott's script from 2009. http://code.google.com/p/db-mysqldump/

About

PHP version of mysqldump cli that comes with MySQL

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 81.1%
  • Shell 10.0%
  • PLpgSQL 8.9%