<?php
if($_GET[action] == install){
	if(!@mysql_connect($_POST[server], $_POST[username], $_POST[password]) || !@mysql_select_db($_POST[database])){//如果没有成功连接数据库
		echo "<script>alert('数据连接失败！');</script>";			//弹出提示信息
	}else{			//否则，连接数据源文件
		$conn = file_get_contents("./conn/conn.php");
		$conn = preg_replace("/mysql_connect\(\"(.+?)\", \"(.+?)\", \"(.+?)\"\)/is", "mysql_connect(\"".$_POST[server]."\", \"".$_POST[username]."\", \"".$_POST[password]."\")", $conn);			//执行正则表达式的搜索和替换
		$conn = preg_replace("/mysql_select_db\(\"(.+?)\"\)/is", "mysql_select_db(\"".$_POST[database]."\")", $conn);		//执行正则表达式的搜索和替换
		$fp = @fopen("./dbconnect.php", "wb");
		if(@fwrite($fp, $conn) && @fclose($fp)){
			$sql_file = file_get_contents("./sql.txt");	//读取数据库文件的内容并返回到字符串中
			mysql_connect($_POST[server], $_POST[username], $_POST[password]);			//连接MySQL服务器
			if(mysql_query($sql_file)){				//如果成功执行脚本文件，则跳转到游戏首页
				header("location:index.php");		//跳转到游戏首页
				exit;
			}
			else{
			echo "<script>alert('数据库安装操作失败！');</script>";
			}
		}
	}
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>数据库安装程序</title>
<style type="text/css">
<!--
body {
	background-image: url(images/bg_pic.gif);
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
td{
	font-size:9pt;
}
.message_box{
	padding:2px 2px 2px 2px;
	border:1px solid #99FF55;
	background:#CCFF05 no-repeat;	
	color:#000000;
	FONT-SIZE: 12px;
	height:20px;
}
.style1 {color: #FFFFCC}
-->
</style></head>

<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><br><br><br></p>
<form name=form method=post action="install.php?action=install">
<table width="259" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#5AA231" bgcolor="#5A3410">
	<tr><td width="72" height="24" align="right"><span class="style1">服务器：</span></td>
	<td width="175" height="24"><input name=server type=text value="localhost" size="20" height="14"></td></tr>
	<tr><td height="24" align="right"><span class="style1">数据库：</span></td>
	<td height="24"><input name=database type=text size="20" height="14"></td></tr>
	<tr><td height="24" align="right"><span class="style1">DB账号：</span></td>
	<td height="24"><input name=username type=text id="username" size="20" height="14"></td></tr>
	<tr><td height="24" align="right"><span class="style1">DB密码：</span></td>
	<td height="24"><input name=password type=text id="password" size="20" height="14"></td></tr>
	<tr align="center"><td height="30" colspan=2><input type=submit value=安装  class="message_box" > &nbsp;
	  <input type="reset" name="Submit" value="清除" class="message_box"></td>
	</tr>
</table>
</form>
</body>
</html>
