Location: PHPKode > projects > MembersGear > membersgear/admin/db_restore.php
<?php
set_time_limit(0);
require_once "../config/config.php";
require_once "../includes/dbbackup_class.php"; 
require_once INCLUDE_DIR."/users_class.php";
$users = new users_class();
if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can restore backup')==false)
{
      Redirect('admin_nopermission.php',true);  
} 

   $backupfolder = PHYSICAL_DIR.'/admin/db_backups/';
    if(!is__writable($backupfolder))
    {
         $message->SetMessage('Please change <b>/admin/db_backups/</b> folders permission to read and write');
         Redirect('admin_db_manage.php');
    }
   
  //backup_tables('192.168.99.3','root','B!g$tore','test');
  $host = MEMBERSGEAR_DB_HOST;
  $user = MEMBERSGEAR_DB_USER;
  $pass = MEMBERSGEAR_DB_PASSWORD;
  $dbname = MEMBERSGEAR_DB_NAME;//DB_NAME; 
// Name of the file
$path = 'db_backups/';
$filename = $path.$_GET['file'];

if(!is_file($filename))
{
   $message->SetMessage('File not found.');
                  
   Redirect('admin_db_manage.php');
   exit();
}
            
$loDbRestore = new dbbackup_class();
 
//////////////////////////////////////////////////////////////////////////////////////////////
 
// Connect to MySQL server
mysql_connect($host, $user, $pass) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($dbname) or die('Error selecting MySQL database: ' . mysql_error());
 
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;
 
    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';')
    {
        // Perform the query
        mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
        // Reset temp variable to empty
        $templine = '';
    }
}

 $lTypes=null;
 $liNow = mktime();
 $lsValues = array($liNow,$_GET['id']);   
 $query = "UPDATE ".TABLE_PREFIX."backup SET lastrestoredon = ? WHERE id=?";

 $lsUpdateRow = $loDbRestore->Update($query,$lsValues,null);
   
   $message->SetMessage('Database restore successfully.');
                  
   Redirect('admin_db_manage.php');
?>
Return current item: MembersGear