<?php

		require_once('../ls_admin/inc/constant.php');
		require_once('../ls_admin/inc/ls_syscode.php');
		

		//writeconstant("lsVer", 1.1 ,"int","insert","//----版本号参数");	

		if($lsVer<1.71)		//设置,更新版本
		{
			updatedb();
			writeconstant("lsVer", 1.181 ,"int","","//----版本号参数");	
		}

/*
更新数据库
*/
function updatedb()
{
	require_once('../ls_admin/inc/conn.php');
	$openck=new cktb();
		
	 //更新数据库处理	
	$filename="../update/updatedb.txt"; 
	$handle = fopen($filename,"r");
	$partstr0="";
	while (!feof ($handle)) 
	{
		$partstr0 =  fgets ($handle, 6000);
		//echo ($partstr0);
		if( strpos(trim($partstr0),"CREATE TABLE ")===0)  //增加表
		{
			$partstr1=	str_replace('CREATE TABLE','',$partstr0);
			$partstr1=	trim(str_replace('`','',$partstr1));
			$partpos=strpos( $partstr1," ");
				//echo $partstr1;
			$partstr11=trim(substr($partstr1,0,$partpos));
			
			$tableName=$partstr11;
			$addTBSQL=$partstr0;
			//echo $tableName."  <br/> ".$addTBSQL."<br/>";
			if($openck->checktable($tableName,$addTBSQL))	echo $openck->ls_msg;

		}
		else
		{
			if( strpos(trim($partstr0),"ALTER TABLE")===0 && strpos($partstr0," ADD ")>0 )  //增加字段
			{
				$partstr1=	str_replace('ALTER TABLE','',$partstr0);
				$partstr1=	trim(str_replace('`','',$partstr1));
				$partpos=strpos( $partstr1," ");
				//echo $partstr1;
				$partstr11=trim(substr($partstr1,0,$partpos));
				$partstr1=	trim(str_replace($partstr11,'',$partstr1));
				$partstr1=	trim(str_replace('ADD','',$partstr1));
				$partpos=strpos( $partstr1," ");
				$partstr12=trim(substr($partstr1,0,$partpos));
				$tableName=$partstr11;
				$fieldName=$partstr12;
				//echo $tableName."   ".$fieldName."<br/>".$partstr0."<br/>";
				if($openck->checkfield($tableName,$fieldName,$partstr0))	echo $openck->ls_msg;

			}
			else
			{
				if( strpos(trim($partstr0), "#")!==0 && trim($partstr0)!="") //不是注释 和空行
				{
					$qureyTBSQL=$partstr0;
					$openck->qureytable($qureyTBSQL);		//执行一般query操作

				}
				else
				{
				}
			}
		}
		
	}
	fclose ($handle);
}




?>