<?php
// Name of the file
$filename = 'limaocms_all.sql';
// MySQL host
$mysql_host = $_POST['local'];
// MySQL username
$mysql_username = $_POST['userid'];
// MySQL password
$mysql_password = $_POST['passid'];
// Database name
$mysql_database = $_POST['dbname'];

// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('连接库连接错误: ' . mysql_error());
mysql_query("set names utf8");
// Select database
mysql_select_db($mysql_database) or die('数据库打开错误: ' . mysql_error());

// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
    continue;

// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
    // Perform the query
    mysql_query($templine) or print('数据执行错误 \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
    // Reset temp variable to empty
    $templine = '';
}
}
 echo "数据导入完成,出于安装考虑请删除安装文件夹<br>";

//搜集资料
$str_tmp="<?php\r\n"; //得到php的起始符
$str_end="?>"; //php结束符
$str_tmp.="$"."local=\"".$mysql_host."\";\r\n"; //加入用户名
$str_tmp.="$"."userid=\"".$mysql_username."\";\r\n"; //加入密码
$str_tmp.="$"."passid=\"".$mysql_password."\";\r\n"; //加入年龄
$str_tmp.="$"."dbname=\"".$mysql_database."\";\r\n";
$str_tmp.=$str_end; //加入结束符

//保存文件
$sf="../include/inc.php"; //文件名
$fp=fopen($sf,"w"); //写方式打开文件
fwrite($fp,$str_tmp); //存入内容
echo "前端配置文件生成ＯＫ<br>";
fclose($fp); //关闭文件

$sf02="../backweb/include/inc.php"; //文件名
$fp02=fopen($sf02,"w"); //写方式打开文件
fwrite($fp02,$str_tmp); //存入内容
fclose($fp02); //关闭文件
echo "后端文件生成ＯＫ<br>";

?>