PHP Classes
elePHPant
Icontem

MySQL Backup: Backup MySQL databases to files with SQL commands

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (15)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2006-01-17 (13 years ago) RSS 2.0 feedStarStarStarStar 71%Total: 5,171 All time: 498 This week: 300Up
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.

Name: Vagharshak Tozalakyan <contact>
Classes: 22 packages by
Country: Armenia Armenia
Age: 39
All time rank: 61 in Armenia Armenia
Week rank: 162 Down1 in Armenia Armenia Equal
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  
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

 Version Control Unique User Downloads Download Rankings  
 0%
Total:5,171
This week:0
All time:498
This week:300Up
User Ratings User Comments (8)
 All time
Utility:92%StarStarStarStarStar
Consistency:82%StarStarStarStarStar
Documentation:78%StarStarStarStar
Examples:85%StarStarStarStarStar
Tests:-
Videos:-
Overall:71%StarStarStarStar
Rank:332
 
Does not save triggers or stored procedures.
8 years ago (Fabian)
35%StarStar
Thank you very much.
10 years ago (nikeman)
80%StarStarStarStarStar
Just great class, and great support from its author.
10 years ago (Sin Kronix)
80%StarStarStarStarStar
Excelent class.
11 years ago (Nando)
77%StarStarStarStar
Very interesting and useful script.
11 years ago (Supieb Klibdaeng)
77%StarStarStarStar
This is the exact class i was looking for.
11 years ago (poomalairaj)
75%StarStarStarStar
Excellent work, very good class, is extremely easy to use and...
11 years ago (Alfredo Cueto)
80%StarStarStarStarStar
Thanks for this great class, I want ask you why you use adsla...
11 years ago (Martin Alurralde)
72%StarStarStarStar