PHP Classes

MySQL Backup: Backup MySQL databases to files with SQL commands

Recommend this page to a friend!

  Author Author  
Name: Vagharshak Tozalakyan <contact>
Classes: 22 packages by
Country: Armenia Armenia
Age: 39
All time rank: 61 in Armenia Armenia
Week rank: 49 Down1 in Armenia Armenia Equal
Innovation award
Innovation award
Nominee: 7x

  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This class can be used to backup MySQL database to files that contain SQL statements to recreate the database.

It can backup whole databases or individial tables. Optionaly it may backup only the structure of tables without data.

It can create files that may optionally be compressed with the gzip algorithm.

The generated backup files can be saved to a server side file, returned as a string of SQL statements or served directly for download.

MySQL database backup class, version 1.0.0


1. Create the instance of MySQL_Backup class.
2. Define necessary properties.
3. Call Execute() method to create backup.

require_once 'mysql_backup.class.php';
$backup_obj = new MySQL_Backup();
$backup_obj->server = 'localhost';
$backup_obj->username = 'username';
$backup_obj->password = 'password';
$backup_obj->database = 'dbname';
$backup_obj->tables = array();
$backup_obj->drop_tables = true;
$backup_obj->struct_only = false;
$backup_obj->comments = true;
$backup_obj->fname_format = 'd_m_y__H_i_s';
if (!$backup_obj->Execute(MSB_DOWNLOAD, '', true))


var $server = 'localhost';
The name of MySQL server.

var $port = 3306;
The port of MySQl server.

var $username = 'root';
Database username.

var $password = '';
Database password.

var $database = '';
Name of the database.

var $link_id = -1;
MySQL link identifier of the current connection. You can set this if you
want to connect the MySQL server by your own.

var $connected = false;
Set true if the connection is already established before calling Execute().

var $tables = array();
Tables you want to backup. All tables in the database will be backed up if
this array is empty.

var $drop_tables = true;
Add DROP TABLE IF EXISTS queries before CREATE TABLE in backup file.

var $struct_only = false;
Only structure of the tables will be backed up if true.

var $comments = true;
Include comments in backup file if true.

var $backup_dir = '';
Directory on the server where the backup file will be placed. Used only if task
parameter equals to MSB_SAVE in Execute() method.

var $fname_format = 'd_m_y__H_i_s';
Default file name format.

var $error = '';
Error message.


function Execute($task = MSB_STRING, $fname = '', $compress = false)
$task - operation to perform: MSB_STRING - return SQL commands as a string;
  MSB_SAVE - create the backup file on the server; MSB_DOWNLOAD - save backup
  file in the user's computer.
$fname - optional name of backup file.
$compress - use GZip compression?

  Classes of Vagharshak Tozalakyan  >  MySQL Backup  >  Download Download .zip .tar.gz  >  Support forum Support forum (15)  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: MySQL Backup
Base name: mysql-backup
Description: Backup MySQL databases to files with SQL commands
Version: 1.0.0
PHP version: -
License: GNU General Public License (GPL)
All time users: 5167 users
All time rank: 495
Week users: 0 users
Week rank: 521 Equal
  Groups   Rate classes User ratings   Trackback   Applications   Files Files  

Group folder image Databases Database management, accessing and searching View top rated classes
Group folder image Systems administration System configuration and management View top rated classes

  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (92%) Good (82%) Sufficient (78%) Good (85%) - - Sufficient (71%) 330
Month: Not yet rated by the users

  Pages that reference this package  
PHP and MySQL to backup (Turkish)
I want to get a complete backup of MySQL with PHP...

Latest pages that reference packages Latest pages that reference packages

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Accessible without login Plain text file execute_db_backup.php Example Example of usage
Plain text file mysql_backup.class.php Class Source
Accessible without login Plain text file readme.txt Doc. Readme

Install with Composer Install with Composer - Download Download all files: mysql-backup.tar.gz
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.