Backup Your Mysql And Restore it By this PHP CLASS

Discussion in 'PHP' started by astkboy2008, Jan 10, 2010.

  1. #1
    tody i get new PHP CLASS to Backup your mysql
    the class name
    IAM Backup 1.2
    by:Iván Ariel Melgrati
    how i can use it?
    Backup method
    first include your class
    require_once("iam_backup.php");
    PHP:
    now start new one
    $backup = new iam_backup("localhost", "mysql", "root", "",
    true, false, false);
    PHP:
    Call the perform backup function and that's it!!!
    $backup->perform_backup();
    PHP:
    Set the parameters: We only set the Database connection. The connection procedure could be in
    an include file
    This will dump the database and prompt the user to download it. No compression is applied here.
      $conn = @mysql_pconnect("localhost","root","");
      if(!$result)     // If no connection, return 0
      {
        echo "An error has occured. Could not connect to the server";
      }
      if(!@mysql_select_db("mysql"))  // If db not set, return 0
      {
        echo "An error has occured. Could not select the MySQL Database";
      }
    
      $backup = new iam_backup($conn);
    
    PHP:
    Call the perform backup function and that's it!!!
    $backup->perform_backup();
    
    PHP:
    Set the parameters: hostname, databasename, dbuser and password(must have SELECT permission to
    the mysql DB)
    Note that this produces a GZip compressed file. You should set the third parameter to false to
    get an SQL file
    This will dump the database into the file located in "./file.sql.gz"
    $backup = new iam_backup("localhost", "mysql", "root", "",
    true, false, true, "./file.sql.gz");
    PHP:

    restore method
    just include the restore class
      require_once("iam_restore.php");
    PHP:
    then use this
    $restore = new iam_restore('path/to/backup/file', "localhost",
    "DBName", "username", "userpwd");
    $restore->perform_restore();
    PHP:
    download it as zip archive:iam_backup-1.2.zip [8.21 KB]
    view source code of the class
    restore:iam_restore.php [3.68 KB]
    Backup:iam_backup.php [13.15 KB]
    examples
    view the open source codes:


     
    astkboy2008, Jan 10, 2010 IP