Download the PHP package druidfi/mysqldump-php without Composer

On this page you can find all versions of the php package druidfi/mysqldump-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mysqldump-php

mysqldump-php

Run tests Total Downloads Monthly Downloads Daily Downloads Latest Stable Version

This is a PHP version of mysqldump cli that comes with MySQL. It can be used for interacting with the data before creating the database dump. E.g. it can modify the contents of tables and is thus good for anonymize data.

Out of the box, mysqldump-php supports backing up table structures, the data itself, views, triggers and events.

mysqldump-php supports:

Requirements

Versions

Version Branch PHP Status Tests
3.x main 8.4+ In development Run tests
2.x 2.x 8.1+ Maintenance Run tests
1.x 1.x 7.4 / 8.0 Legacy

Upgrading from 2.x to 3.x

The dump output and the day-to-day API — constructor, start(), the transform/info hooks, setTableWheres()/setTableLimits() and the dump settings with their defaults — are unchanged from 2.x. The following changes may require action:

Also fixed in 3.x with no action needed: 2.x settings validation rejected the Zstd, Lz4 and Gzipstream compression methods due to a mismatch between the allowed values and the factory; they now validate correctly.

Installing

Install using Composer:

Getting started

The sections below cover the most common use cases. All configuration options are listed under Tests section describes how the output is compared against native mysqldump.

Error handling

All exceptions thrown by the library extend Druidfi\Mysqldump\Exception\MysqldumpException, which itself extends the native Exception. Catch the base class to handle any library error, or a subclass to react to a specific failure:

Providing your own database connection

By default the connection is built from the DSN, username and password given to the constructor. If you need to reuse an existing PDO instance or apply a custom connection strategy, implement Druidfi\Mysqldump\ConnectionInterface and inject it before starting the dump:

getHost() and getDbName() are used in the dump file header comments and in the SHOW/CREATE DATABASE statements, so return the values of the database being dumped.

Changing values when exporting

You can register a callable that will be used to transform values during the export. An example use-case for this is removing sensitive data from database dumps:

Anonymization recipes

For the common GDPR-sanitization cases the Anonymizer class provides ready-made, dependency-free helpers. Anonymizer::columnMap() builds a row-transform hook from a table => column => transformer map; tables and columns not in the map pass through untouched:

Notes on the helpers:

Anonymization here means the dump never contains the original values; it is not a substitute for access control on the source database itself.

For realistic-looking fake data (names, addresses, phone numbers) the hooks combine well with FakerPHP — see docs/faker.md for recipes, including how to keep Faker output deterministic so joins and unique indexes survive.

Filtering rows when exporting

The same hook can drop rows entirely: return null instead of the row and it is left out of the dump. Unlike the where/setTableWheres() settings this filters in PHP, so it works for conditions that are hard to express in SQL or that depend on data outside the database:

Skipped rows are not counted in the dump's row-count comments or in the info hook's rowCount. Prefer where/setTableWheres() when the condition is expressible in SQL — filtering in the database avoids transferring the skipped rows at all.

Getting information about the dump

You can register a callable that will be used to report on the progress of the dump

For tables the $info array contains name, rowCount and completed (set to true once the table has been fully dumped).

Table specific export conditions

You can register table specific 'where' clauses to limit data on a per table basis. These override the default where dump setting:

[!WARNING] The where dump setting, setTableWheres() and setTableLimits() values are inserted into the dump's SELECT statements as raw SQL by design — that is what makes arbitrary conditions possible. They are not escaped or validated, so never build them from untrusted input (request parameters, user-supplied data, etc.).

Table specific export limits

You can register table specific 'limits' to limit the returned rows on a per table basis:

You can also specify the limit as a two-value array, which maps to MySQL's LIMIT offset, row_count syntax: the first value is the offset and the second is the number of rows

Dumping to cloud storage and other streams

The filename given to start() is opened with PHP's fopen(), so any registered stream wrapper works as a dump target: built-in ones like php://stdout or ftp://, and cloud storage wrappers registered by the respective SDKs — gs:// by google/cloud-storage, s3:// by aws/aws-sdk-php, or any league/flysystem adapter exposed as a wrapper. No cloud SDK dependencies are needed in this library:

[!NOTE] The Gzip and Bzip2 compression methods use gzopen()/bzopen(), which only work on local files. When dumping to a stream wrapper, use Gzipstream (identical gzip output written through fopen()), Zstd, Lz4 or None.

Dump Settings

Dump settings can be changed from default values with the 4th argument of the Mysqldump constructor. PDO options can be passed as the 5th argument:

All options:

The following option is deprecated. Passing it triggers a deprecation notice, and it will be removed in a future version; use init_commands to control FOREIGN_KEY_CHECKS manually if needed.

Privileges

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:

Security considerations

The library never stores credentials — they are passed to the constructor and used only to open the PDO connection. Keeping them safe is the calling application's responsibility. Do not hardcode credentials in code or commit them to version control; read them from environment variables or a secret manager instead:

Remember that the where, setTableWheres() and setTableLimits() values are raw SQL and must not be built from untrusted input — see the warning under Table specific export conditions.

To report a vulnerability, see SECURITY.md.

Tests

The testing script creates and populates a database using all possible datatypes. Then it exports it using both mysqldump-php and mysqldump, and compares the output. Only if it is identical tests are OK.

Some tests are skipped if mysql server doesn't support them.

A couple of tests are only comparing between original sql code and mysqldump-php generated sql, because some options are not available in mysqldump.

Local setup for tests:

Credits

Forked from Diego Torres's version which have latest updates from 2020. Use it for PHP 8.1 and older. https://github.com/ifsnop/mysqldump-php

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

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

License

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


All versions of mysqldump-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
composer-runtime-api Version ^2
ext-pdo Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package druidfi/mysqldump-php contains the following files

Loading the files please wait ...