<?php
	require_once('_approot.php');	

	$restoredb=$restoreDBName;

	$conn=mysqli_connect($host,$username,$password) or die ("can't connect DBS");
	$restoredblink=mysqli_select_db($conn,$restoredb);
	
	$filename=$backupSQLFile;
	
	if (!file_exists ($filename))
	{ 
	   die( $filename." is not exist!"); 	   
	}

	$strlength=$maxLenSQLStr;
	$allnum =0;
	$num =0;
	$handle = fopen ($filename,"r");
	$partstr="";
	$partstr0="";
	while ($partstr0 =  fgets ($handle, 6000)) 
	{
		//echo $partstr0. "ss";
		//echo substr(substr ($partstr0,-3),0,1);
		if(substr(substr ($partstr0,-3),0,1)==";")// get the end of line ;
		{
			$partstr.=$partstr0;
			//echo "11";
		}
		else
		{
			$partstr.=$partstr0;
			//echo "22";
			continue;
		 }
		//echo $partstr. "ss";
		$num=strlen($partstr);
   	 	$allnum += $num;
		$sqlstr=$partstr;
		$gettablename=$partstr;
		$tablename="";
		$iftablename=strpos($gettablename,"create table `");
		$tablenamestart=strlen("create table `");
		$tablenameend=strpos($gettablename,"` (`");
		$tablenamelen=$tablenameend-$tablenamestart;

		if($iftablename===0)
		{
			$tablename=substr($gettablename,$tablenamestart,$tablenamelen);
		}
		
		$query=mysqli_query($conn,$sqlstr);
		if($query)
		{
			if($tablename=="")
			{echo " 已经写入数据 ".$num." 字节!<br/>";}
			else
			{echo "创建表 ".$tablename." OK! <br/>";}
			
		}
		$partstr="";
		
	}
	echo "恢复数据库 ".$restoredb." 完成!<br/>";
	fclose ($handle);

	
?>

