|
|
3 vuotta sitten | |
|---|---|---|
| .. | ||
| src/Ifsnop/Mysqldump | 3 vuotta sitten | |
| tests | 3 vuotta sitten | |
| .gitignore | 3 vuotta sitten | |
| .scrutinizer.yml | 3 vuotta sitten | |
| .travis.yml | 3 vuotta sitten | |
| README.md | 3 vuotta sitten | |
| composer.json | 3 vuotta sitten | |
| phpunit.xml | 3 vuotta sitten | |
Requirements | Installing | Getting started | API | Settings | PDO Settings | TODO | License | Credits
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.
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 -
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 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',
'skip-comments' => false,
'skip-dump-date' => false,
);
$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);
The following options are now enabled by default, and there is no way to disable them since they should always be used.
To dump a database, you need the following privileges :
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?
Format all code to PHP-FIG standards. http://www.php-fig.org/
This project is open-sourced software licensed under the GPL license
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