<table cellspacing="2" cellpadding="1" width="670" align="center" border="0">
  <tbody>
    <tr>
      <td height="74"> <span class="heading">PHPStat Counter 检查目录属性</span>
        <hr align="left" size="1" width="100%"/>
        <form id="form1" name="form1" method="get" action="">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="28%" rowspan="5"><table width="90%" height="200" border="0" cellpadding="5" cellspacing="3" style="border-right:2px solid #cccccc;">
                <tr>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>1.检查目录属性</td>
                </tr>
                <tr>
                  <td>2.检查参数设置</td>
                </tr>
                <tr>
                  <td><span class="heading">3.安装数据库</span></td>
                </tr>
                <tr>
                  <td>4.安装完成</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                </tr>
              </table></td>
              <td></td>
            </tr>
            
            <tr>
              <td><? if($errors) {echo $errors;exit;}?></td>
            </tr>
            <tr>
              <td><? if($errors2) {echo $errors2;exit;}?></td>
            </tr>
            <tr>
              <td height="59">
		<?
		
		$memory_limit = @get_cfg_var("memory_limit");
		$memory_limit = substr($memory_limit,0,-1);
		
		if($memory_limit < 3)
		{
			echo "<br>现在开始检查PHP.INI配置文件属性设置<br>\n";
			echo "请将配置文件中的 '<FONT COLOR=\"#FF0000\">memory_limit</font>' 选项设置为 \" 3M  \" ，或者更多，以便安装数据库，即：memory_limit = 3M <br>强烈建议您修改此选项，否则影响您的安装&nbsp;&nbsp;&nbsp;<A HREF=http://bbs.phpstat.net/read.php?tid=81 target=_blank>[点击查看详情]</A><br>\n";
			$error = true;
			fputs($fp,"\n######".date('Y-m-d H:s')." 请将PHP.INI配置文件中的 memory_limit 选项设置为 3M 即：memory_limit = 3M");
		}
		else
		{
		echo '<br>ip数据由于很大分别使用4个文件安装,请耐心等待 ~_~ 大约需要几分钟 如果IP数据表出现错误请重新安装';
		$d = dir("./install");
		while (false !== ($entry = $d->read()))
		{
			if ( ereg ("^structure_(.*)\.sql", $entry, $ret ) ) 
			{
				$structure[$ret[1]] = $entry;
			}
			else if( ereg ("^data_(.*)\.sql", $entry, $ret ) )
			{
				$data[$ret[1]] = $entry;
			}

		}
		$d->close();

		foreach( $structure as $key => $val )
		{			
			echo '<br>建立数据表 ' . $key . "  &nbsp;&nbsp;&nbsp;\n";
			$content = str_replace( 'PREFIX_' , DB_PREFIX, file_get_contents( './install/' . $val ) );
			$vrs	 = @mysql_query("select version() as version");
			$vrsrow  = @mysql_fetch_array($vrs);
			$Version = explode('.',$vrsrow[version]);
			$Versionint = $Version[0];
			$Versionint .= $Version[1];
			if( $Versionint > 40 )
			$content = ereg_replace(";"," DEFAULT CHARACTER SET ".DB_CHARSET." ;",$content);
			mysql_query( $content );
			if(mysql_error())
			echo mysql_error();
			else
			echo "完成";
		}
		
		echo "<br>\n";		
		foreach( $data as $key => $val )
		{				
			echo '<br>插入数据 ' . $key . "<br>\n";
			$content = file( './install/' . $val );
			foreach( $content as $sql )
			{
				$sql = str_replace( 'PREFIX_' , DB_PREFIX, $sql );
				mysql_query( $sql );
			}
		}
		
		echo "<br>\n";
		echo "安装数据库的时候可能会出现一些错误提示,比如如果你是第二次安装,会提示表已经存在的错误信息.如果你确定错误不影响安装,那么请点下一步!<br>\n";
		echo "<br><br><input name=\"Submit\" type=\"button\" class=\"button\" onclick=\"window.location='install.php?step=4'\" value=\"继　续　安　装\">";
		}

		?></td>
            </tr>
            <tr>
              <td height="59">&nbsp;</td>
            </tr>
          </table>
        </form>
        <p>&nbsp;</p></td>
    </tr>
    <tr>
      <td height="18">&nbsp;</td>
    </tr>
  </tbody>
</table>
