<?php
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/conn_var.php');
	require_once('inc/ls_syscode.php');
	$opendb=new mydb();
	$restoredb=$restoreDBName;

	$conn=mysql_connect($host,$username,$password) or die ("can't connect DBS");
	$restoredblink=mysql_select_db($restoredb,$conn);
	
	$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=mysql_query($sqlstr);
		if($query)
		{
			if($tablename=="")
			{echo " 已经写入数据 ".$num." 字节!<br/>";}
			else
			{echo "创建表 ".$tablename." OK! <br/>";}
			
		}
		$partstr="";
		
	}
	echo "恢复数据库 ".$restoredb." 完成!<br/>";
	fclose ($handle);

	
?>

