PHP Classes

Danen MySQL Backup: Create database backup SQL statements using MySQLi

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 512 All time: 5,755 This week: 72Up
Version License PHP version Categories
danen-mysql-backup 2Freely Distributable5.4PHP 5, Databases, Systems administration
Description 

Author

This class can create database backup SQL statements using MySQLi.

It can connect to a MySQL database table using the MySQLi extension and generates a file with SQL statements that can be used later to restore the table definition and record data of one or more database tables.

The class creates a backup file with a unique name and returns the backup file name.

Picture of Gerry Danen
  Performance   Level  
Name: Gerry Danen <contact>
Classes: 3 packages by
Country: Australia Australia
Age: 74
All time rank: 219632 in Australia Australia
Week rank: 163 Up2 in Australia Australia Up

Recommendations

Good backup/restore MySQL
Script to backup and restore databases

Example

<?php
// example to do a full database backup

require_once 'danenMysqlBackup.class.php';


$B = new danenMysqlBackup();

$backupSqlFile = $B->backupStart();

if (
$backupSqlFile )
{
   
$backupSqlFile = basename( $backupSqlFile );
    echo
"Created: $backupSqlFile";
}
else
    echo
"ERROR: backup failed.";



Details

I needed a MySQL database backup function that I could call from a script and would not rely on mysqldump or phpMyAdmin. I found a class by Hossein Sarlak that used the older mysql interface. I wanted the newer mysqli interface, so I set out rebuilding the class when I could not locate Hossein Sarlak. I found his script for sale for $25, but no indication whether it was updated. This script is free. Use as you see fit. Make sure to read all comments. There are some customizations needed. Gerry Danen 26 February 2015

  Files folder image Files (3)  
File Role Description
Plain text file danenMysqlBackup.class.php Class Main class file
Accessible without login Plain text file doBackup.php Example Shows how to call the class
Accessible without login Plain text file readme.txt Doc. Some extra information

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:512
This week:0
All time:5,755
This week:72Up