Download the PHP package dimtrovich/db-dumper without Composer
On this page you can find all versions of the php package dimtrovich/db-dumper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dimtrovich/db-dumper
More information about dimtrovich/db-dumper
Files in dimtrovich/db-dumper
Package db-dumper
Short Description Dump and restore the contents of a database
License MIT
Homepage https://github.com/dimtrovich/php-db-dumper
Informations about the package db-dumper
EN | FR
Backup and restore database content
Db Dumper is a tool that offers you a simple and efficient way to export and import your database in PHP. It is somewhat of a PHP version of the command-line tool mysqldump that comes with MySQL, without dependencies, with output compression and reasonable default parameters.
Db Dumper supports backing up table structures, the data itself, views, triggers, and events.
Features
Db Dumper supports:
- outputting binary blobs in hexadecimal form.
- resolving view dependencies (using substitute tables).
- backing up stored routines (functions and procedures).
- backing up events.
- extended and/or complete insertion.
- MySQL 5.7 virtual columns.
insert-ignore, like aREPLACEbut ignoring errors if a duplicate key exists.- modifying database data on the fly during backup, using
hooks. - direct backup to Google Cloud storage via a compressed stream wrapper (GZIPSTREAM).
Db Dumper is designed to work with the main current database management systems. The list below outlines their support:
- MySQL (supported)
- SQLite (supported)
- PostgreSQL (in progress)
- Oracle (not supported)
Prerequisites
- PHP 7.4+
- *MySQL 5+
- *SQLite 3+
- PDO
Installation
Using Composer:
After installing this package, you must first ensure that you have access to a PDO instance as the export and import systems need it.
Data Export (backup)
Data export is the main functionality of this package. Db Dumper offers you a simple API to backup your database with the same options offered by native MySQL or PostgreSQL commands (mysqldump / pgrestore)
Modifying values during export
You can register a callable that will be used to transform values during export. A typical use case is removing sensitive data from database backups:
Getting information about table export
You can register a callable that will be used to report the progress of the backup:
Table-specific export conditions
You can define table-specific WHERE clauses to limit the data of tables that can be exported. These clauses override the default where parameter:
Table-specific export limits
You can also define table-specific limits to limit the number of records that will be saved for each table:
Exporter configuration options
The constructor of the Exporter class accepts a third parameter which is an array designating the data export options.
Data Import (Restore)
Just like with data export, Db Dumper provides you with a simple API to restore your database from a backup file (.sql, .gz, .gzip, .bz2, .bzip2).
The file extension of the restore file determines the type of compression to use:
.sqlNo compression, it's a plain SQL file..gz,.gzipGZIP compression, the importer will decompress the file before proceeding with the database restoration. Make sure your PHP installation has theZlibextension enabled before using such a dump..bz2,.bzip2BZIP2 compression, the importer will decompress the file before proceeding with the database restoration. Make sure your PHP installation has theBzlib2extension enabled before using such a dump.
Get Information on Table Import
You can register a callable that will be used to report the progress of the restoration:
Errors
To back up a database, you need the following privileges:
- SELECT
- To back up table structures and data.
- SHOW VIEW
- If a database contains views, otherwise you will get an error.
- TRIGGER
- If a table contains one or more triggers.
- LOCK TABLES
- If the "lock tables" option is enabled.
Use SHOW GRANTS FOR user@host; to check the user's privileges. See the following link for more information:
What are the minimum privileges required to get a backup of a MySQL database schema?
To restore a database, you need the following privileges:
- ALTER
- Required if your backup file contains table alteration instructions.
- CREATE
- Required if your backup file contains table creation instructions.
- CREATE ROUTINE
- Required if your backup file contains routine creation instructions.
- CREATE VIEW
- Required if your backup file contains view creation instructions.
- DELETE
- Required if your backup file contains data deletion instructions.
- DROP
- Required if your backup file contains table or view deletion instructions.
- INSERT
- Required if your backup file contains data insertion instructions into tables.
- UPDATE
- Required if your backup file contains data modification instructions in tables.
Tests
The unit tests for this package are written using the Kahlan library. The tests cover SQLite, but tests for MySQL have not been written, although tests have been conducted in a real environment. PRs in this direction are welcome.
Todo
- Write more tests, also test with MariaDB.
- Support for other database drivers (PostgreSQL, Oracle, MS Server, MongoDB).
Contribution
Please see CONTRIBUTING for more details.
License
This project is open-source software licensed under the MIT license. Please see the License File for more information.
Credits
Although significantly modified, the code for DB Dumper's exporter was inspired by MySQLDump - PHP maintained by Diego Torres. We would like to thank him.
That said, note that this package was created by Dimitri Sitchet Tomkeu and is maintained by All Contributors.

