2. Restore the database [db_restore.php]
// My database information is stored in the config.php file, so load this file. If yours is not stored in this file, just comment this line;
require_once ((dirname(__FILE__).'/../../include/config.php'));
if ( isset ( $_POST['sqlFile'] ) )
{
$file_name = $_POST['sqlFile']; //SQL file name to be imported
$dbhost = $cfg_dbhost; //Database host name
$dbuser = $cfg_dbuser; //Database user name
$dbpass = $cfg_dbpwd; //Database password
$dbname = $cfg_dbname; //Database name
set_time_limit(0); //Set the timeout to 0, which means it will always be executed. When php is invalid in safe mode, it may cause the import to time out. In this case, it is necessary to import in sections
$fp = @fopen($file_name, "r") or die("Cannot open SQL file $file_name" );//Open file
mysql_connect($dbhost, $dbuser, $dbpass) or die("Cannot connect to database $dbhost");//Connect to database
mysql_select_db($dbname) or die ("Cannot open Database $dbname");//Open the database
echo "
Clearing the database, please wait....
";
$result = mysql_query("SHOW tables ");
while ($currow=mysql_fetch_array($result))
{
mysql_query("drop TABLE IF EXISTS $currow[0]");
echo "Clear the data table【". $currow[0]."] Success!
";
}
echo "
Congratulations on successfully cleaning MYSQL
";
echo "Executing Import database operation
";
//MySQL command to import database
exec("mysql -u$cfg_dbuser -p$cfg_dbpwd $cfg_dbname < ".$file_name);
echo "< ;br>Import completed! ";
mysql_close();
}
?>