1. Summary

PHPMyExport is a PHP written script. It allows webmasters, administrators and any database users to dump and store the databases.

PHPMyExport is an easy, fast and powerful PHP class, which allows multiple databases dump. This tool is to replace the mysqldump tool, unavailable for hosted websites, not user-friendly or just too complicated to use. It provides a web based interface, for an easy going backup and security system.

Changes with previous version:

  • PHPMyExport is now a PHP5 clean and tidy class. It uses the power of the Object Oriented Programming (OOP). Any other web application may now interact simply with it.

  • PHPMyExport embeds ADODB. It supports many database types: mysql, mysqli, postgres, sqlite, mssql, access, ... (help is needed to test on all those databases. Please feel free to contribute)

  • PHPMyExport can list the databases and the tables of a given host. It allows you to choose very precisely what database/table you wanna backup.

  • PHPMyExport supports many dump methods: you can either display the dump, append it into in file, upload it on a FTP Server, force the download of the file or reinject directly the dump in another host/database/table.

  • PHPMyExport has now a debug mode. Each step is watched, each error is catched. You exactly know what is blocking the application.

  • PHPMyExport supports new dump options, and there are more to come...

2. Requirements

PHPMyExport new version is written in PHP5. Therefore it requires:

3. Installation

3.1. Using sources

At first, check the requirements. If everything is OK, download the source archive (Until the first official release, there is not source archive). Uncompress it into a Web accessible directory (/var/www/phpmyexport for instance). Point your browser to http://<your_hostname>/phpmyexport. You're done Smile :-)

3.2. Using Bazaar sources

You may checkout the source repository in order to always be up to date. To checkout, run: cd /path/to/your/directory bzr checkout

Caution: the trunk is the development directory. Code may be unstable. Trunk is mostly used for testing purposes.

4. The PHPMyExport engine

4.1. Instantiate the class

At first, when you need the PHPMyExport engine, you need to include the class:

include 'phpmyexport.class.php';

... and to instantiate it. PHPMyExport expects at least one parameter: the DNS string (check ADODB Documentation for details):

$app = new PHPMyExport('mysql://root:password@localhost');

If you want to run in debug mode (error messages will be printed out), do:

$app = new PHPMyExport('mysql://root:password@localhost', true);

4.2. Setting Options

Here is the list of the options you may set:

'export_structure'              => true,
'export_datas'                  => true,
'query_type'                    => array('insert', 'replace'),
'use_transaction'               => false,
'add_create_database'           => true,
'add_drop_database'             => true,
'add_drop_table'                => true,

4.2.1. export_structure

  • true (default): will add queries to create databases and tables

  • false: will not create databases or tables

4.2.2. export_datas

  • true (default): tables content will also be dumped

  • false: does not dump tables content

4.2.3. query_type

  • insert (default): will output INSERT INTO queries

  • replace: will output REPLACE INTO queries

4.2.4. use_transaction

  • true: transactions will be used. It depends on the database engine. Transaction is rollbacked when an error occurs
  • false (default): no transaction is used

4.2.5. add_create_database

  • true (default): add the CREATE DATABASE query for each database you dump

  • false: does not create databases

4.2.6. add_drop_database

  • true (default): add the DROP DATABASE IF EXISTS query for each database you dump

  • false: does not drop existing databases

4.2.7. add_drop_table

  • true (default): add the DROP TABLE IF EXISTS query for each table you dump

  • false: does not drop existing tables

4.2.8. more to come...

You've got ideas, questions? You wanna contribute? See here:

To set an option, do:

$app->setOption('<option_name>', '<option_value>');

For example:

$app->setOption('add_drop_database', false);

4.3. Setting dump method

PHPMyExport offers you 4 ways to export your dump:

4.3.1. output

If you choose this option, the dump will be printed out in your browser (or client). That can be convenient for small and medium dumps. Be careful with big and massive dumps: browsers are not keen to display thousands and thousands of lines.


4.3.2. download

PHPMyExport will trigger a download box. You will be able to save the dump on your local machine. The option accepts one optional parameter:

  • filename (optional): the dump filename

$app->setDumpMethod('download', array('filename'=>'dump.sql'));

4.3.3. write

PHPMyExport will open a file on the server hard drive and append the dump into it. The option accepts two parameters:

  • path (mandatory): the path the file will be saved in. Make sure PHP has write access in this directory

  • filename (optional): the file name

$app->setDumpMethod('write', array('path'=>'/home/axel', 'filename'=>'dump.sql'));

4.3.4. FTP upload

PHPMyExport will open a distant FTP connection in order to upload the dump (new feature, more details to come)

4.3.5. inject

PHPMyExport can now open a new database connection to append the dump. The options accepts one mandatory argument:

  • DNS driver (check ADODB Documentation for details): <driver>://<username>:<password>@<hostname>/<database>

4.4. Choose the databases and the tables to dump

PHPMyExport can list for you the databases and the tables of the current connection.

To get the databases list, just do:

$databases = $app->getDatabasesList();

To get the tables list for a given database, just do:

$table = $app->getTablesList('<database>');

Now you have to build the databases and tables list you wanna dump. You may use the * wildcard meaning: everything. You may choose all databases and all tables or choose one database and all its tables or choose just a couple of tables. You can actually do whatever you want. Here is an example:

$todump = array(
        'mysql'=> array('user', 'db'),

In the example, you're going to backup:

  • two tables from the mysql database: user and db

  • all tables from the information_shema database

You can also do :

$todump = array('*');

You're going to backup all databases.

4.5. Start the dump

Now you're done with the options. You probably want to start the dump now Smile :-) Just use the goDumpNow() function. This function requires one argument: the list of databases and tables you've generated above. The result is:


5. Demonstration version

Demo version can be found here:

  • Driver: mysql
  • Host: localhost
  • User: phpmyexport
  • Pass: demo

Warning: the demo might not be fully fonctionnal as the project is still under development

6. Notes

PHPMyExport is still under heavy development. This a beta version. For now, only the engine is being released. Unlike the previous versions, there is no graphical interface (GUI) for this version. Once the engine is ready, that will be my next task. Actually, anyone could contribute and help at developing and designing a GUI for PHPMyExport

This page also needs modifications. This is the very first version, and I probably forgot a couple of things ;-).

I support the goPHP5 website.

7. Class Description - Methods list

 * __construct() : this method is called on startup, initiates connection and options
 * $driver: DSN string
 * $debug: whether to run in debug mode or not
public function __construct($driver, $debug = false)

 * Sets an option
public function setOption($name, $value)

 * Returns an option value
private function getOption($name)

 * prepareDump() : analyses and parses the dump options
 * $content: list of databases/tables to dump
private function prepareDump($content = array())

 * goDumpNow(): start the dump process
 * $content: list of databases/tables to dump
public function goDumpNow($content = array())

 * What dump method to use
 * $method: the method
 * $options: method specific options
public function setDumpMethod($method, $options = array())

 * Checks that arguments are valid
private function checkArguments($options)

 * Starts the method stuff
private function prepareMethod()

 * Outputs a row of the dump
 * depends on the method
private function outputDump($row)

 * getFilename(): return the dump filename,
 * automatically generated or user generated
 * adds the / if applicable
private function getFilename()

 * getDatabasesList(): returns an exploitable list of databases
public function getDatabasesList()

 * getTablesList(): returns an exploitable list of tables for a given database
 * $database: database to work on
public function getTablesList($database)

 * connect(): initiates the connection to the database
 * $type: can be set to "read" or "write"
private function connect($type = 'read')

 * listDatabases(): gather the databases
private function listDatabases()

 * listTables(): gather the tables
private function listTables($database)

 * raiseError():: logs and displays if debug mode on
 * $content: message to display
private function raiseError($content)

CategorySpec CategoryDocumentation

PHPMyExport (last edited 2008-08-06 17:00:17 by localhost)