PHP Classes

MySQL Backup: Backup MySQL databases to files with SQL commands

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 70%Total: 5,188 All time: 510 This week: 488Up
Version License Categories
mysql-backup 1.0.0GNU General Publi...Databases, Systems administration
Description 

Author

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.

Picture of Vagharshak Tozalakyan
Name: Vagharshak Tozalakyan <contact>
Classes: 22 packages by
Country: United States United States
Age: 44
All time rank: 61 in United States United States
Week rank: 195 Down20 in United States United States Down
Innovation award
Innovation award
Nominee: 7x

Details

MySQL database backup class, version 1.0.0 HOW TO USE 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)) { die($backup_obj->error); } PUBLIC PROPERTIES 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. PUBLIC METHODS 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?

  Files folder image Files (3)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:5,188
This week:0
All time:510
This week:488Up
User Ratings User Comments (8)
 All time
Utility:91%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:78%StarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:70%StarStarStarStar
Rank:268
 
Does not save triggers or stored procedures.
13 years ago (Fabian)
35%StarStar
Thank you very much.
15 years ago (nikeman)
80%StarStarStarStarStar
Just great class, and great support from its author.
16 years ago (Sin Kronix)
80%StarStarStarStarStar
Excelent class.
16 years ago (Nando)
77%StarStarStarStar
Very interesting and useful script.
16 years ago (Supieb Klibdaeng)
77%StarStarStarStar
This is the exact class i was looking for.
16 years ago (poomalairaj)
75%StarStarStarStar
Excellent work, very good class, is extremely easy to use and...
16 years ago (Alfredo Cueto)
80%StarStarStarStarStar
Thanks for this great class, I want ask you why you use adsla...
16 years ago (Martin Alurralde)
72%StarStarStarStar