<?php
error_reporting(0);
@ini_set("short_open_tag", "on");
date_default_timezone_set('PRC');
$mysql=require("../fuckyoumdyiscyab/db.php");
$dbhost=$mysql['DB_HOST'];
$dbport=$mysql['DB_PORT'];
$dbuser=$mysql['DB_USER'];
$dbpassword=$mysql['DB_PWD'];
$dbmysql=$mysql['DB_NAME'];
if($con = mysql_connect($dbhost,$dbuser,$dbpassword)){
	mysql_select_db($dbmysql, $con);
}else{
	exit('数据库链接失败！');
}
mysql_query("set names utf8"); 
$tableqz=$mysql['DB_PREFIX'];
$result=mysql_query("select * from {$tableqz}webconfigs");
while($row = mysql_fetch_array($result)){ 
	$config[$row['vkey']]=$row['value'];
}
error_reporting(E_ALL & ~E_NOTICE);
	@header('Content-Type: text/html; charset=UTF-8');
	if(file_exists('tgyd.lock')){
		exit('已经更新完成！如需重新更新，请删除update目录下的tgyd.lock!');
	}
	$step=is_numeric($_GET['step'])?$_GET['step']:'1';
?>
<?php if($step=='1'){

			if(!$con=mysql_connect($dbhost.':'.$dbport,$dbuser,$dbpassword)){
				echo'<script language=\'javascript\'>alert("连接数据库失败，'.mysql_error().'");history.go(-1);</script>';
			}elseif(!mysql_select_db($dbmysql,$con)){
				echo'<script language=\'javascript\'>alert("选择的数据库不存在，'.mysql_error().'");history.go(-1);</script>';
			}else{
				$data="<?php
return array(
	'DB_HOST'               =>  '{$dbhost}',
    'DB_NAME'               =>  '{$dbmysql}',
    'DB_USER'               =>  '{$dbuser}',
    'DB_PWD'                =>  '{$dbpassword}',
    'DB_PORT'               =>  '{$dbport}',
    'DB_PREFIX'             =>  'klmz_',
);";
				if(file_put_contents('../fuckyoumdyiscyab/db.php',$data)){
					$sqls=file_get_contents("update.sql");
					$explode = explode(";",$sqls);
					$num = count($explode);
					foreach($explode as $sql){
						if($sql=trim($sql)){
							mysql_query($sql);
						}
					}
					if(mysql_error()){
						echo'<script language=\'javascript\'>alert("导入数据表时错误，'.mysql_error().'");history.go(-1);</script>';
					}else{
						@file_put_contents('tgyd.lock','');
						echo'数据库升级完成';
				?>
				<?php
					}
				}else{
					echo'<script language=\'javascript\'>alert("请确认空间目录中是否存在inc文件夹 若无 请创建名为inc的文件夹");history.go(-1);</script>';
				}
			}
		
	
}elseif($step=='4'){


?>


<?php }?>