Giter Site home page Giter Site logo

tridungle / mysqldump-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ifsnop/mysqldump-php

0.0 2.0 0.0 1.05 MB

PHP version of Linux's mysqldump in terminal "$ mysqldump -u username -p...".

Home Page: https://github.com/ifsnop/mysqldump-php

PHP 87.61% Shell 4.75% PLpgSQL 7.64%

mysqldump-php's Introduction

MySQLDump - PHP

Requirements | Installing | Getting started | API | Settings | PDO Settings | TODO | License | Credits

Build Status Scrutinizer Quality Score Latest Stable Version

This is a php version of linux's mysqldump in terminal "$ mysqldump -u username -p...", without dependencies, output compression and sane defaults.

Out of the box, MySQLDump-PHP supports backing up table structures, the data itself, views and triggers.

Requirements

  • PHP 5.3.0 or newer
  • MySQL 4.1.0 or newer
  • PDO

Installing

Using Composer:

$ composer require ifsnop/mysqldump-php:1.*

Or via json file:

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

Using Curl:

$ curl --silent --location https://github.com/ifsnop/mysqldump-php/archive/v1.4.1.tar.gz | tar xvfz -

Getting started

With Autoloader/Composer:

<?php

use Ifsnop\Mysqldump as IMysqldump;

try {
    $dump = new IMysqldump\Mysqldump('database', 'username', 'password');
    $dump->start('storage/work/dump.sql');
} catch (\Exception $e) {
    echo 'mysqldump-php error: ' . $e->getMessage();
}

?>

Plain old PHP:

<?php

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

?>

Refer to the wiki for some examples and a comparision between mysqldump and mysqldump-php dumps.

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(),
    'exclude-tables' => array(),
    'compress' => 'None',
    'no-data' => false,
    'add-drop-table' => false,
    'single-transaction' => true,
    'lock-tables' => false,
    'add-locks' => true,
    'extended-insert' => true,
    'disable-keys' => true,
    'where' => '',
    'no-create-info' => false,
    'skip-triggers' => false,
    'add-drop-trigger' => true,
    'hex-blob' => true,
    'databases' => false,
    'add-drop-database' => false,
    'skip-tz-utc' => false,
    'no-autocommit' => true,
    'default-character-set' => 'utf8',
);

$pdoSettingsDefaults = array(
    PDO::ATTR_PERSISTENT => true,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    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

The following options are now enabled by default, and there is no way to disable them since they should always be used.

PDO Settings

Errors

To dump a database, you need the following privileges :

  • SELECT
    • In order to dump table structures and data.
  • SHOW VIEW
    • If any databases has views, else you will get an error.
  • TRIGGER
    • If any table has one or more triggers.
  • LOCK TABLES
    • If "lock tables" option was enabled.

Use SHOW GRANTS FOR user@host; to know what privileges user has. See the following link for more information:

Which are the minimum privileges required to get a backup of a MySQL database schema?

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 GPL license

Credits

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

Adapted and extended by Michael J. Calkins. https://github.com/clouddueling

Currently maintained and developed by Diego Torres. https://github.com/ifsnop

mysqldump-php's People

Contributors

ifsnop avatar clouddueling avatar gwarnants avatar barrymieny avatar judgej avatar piotrantosik avatar alexsegura avatar bitdeli-chef avatar caseyfw avatar daveismynamecom avatar jonas-veselka avatar tantegerda1 avatar lukeb avatar maikeldaloo avatar rvanlaak avatar savagecore avatar

Watchers

James Cloos avatar Trí Dũng Lê avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.