<?php
@header("content-Type: text/html; charset=utf-8");
error_reporting(0);

require_once('../link.php'); 

$dbcharset = 'utf8';
$sqlfile = '../install/ly_data.sql';//本机导出的Sql文件
 
if(!is_readable($sqlfile)) {
 exit('数据库文件不存在或者读取失败');
}
$fp = fopen($sqlfile, 'rb');
$sql = fread($fp, 2048000);
fclose($fp);
 
$conn=mysql_connect($se_name,$sedb_name ,$db_pass);//指定数据库连接参数
if (!$conn)
{
  die('Could not connect: ' . mysql_error());
}
 
function runquery($sql) {
 global $dbcharset, $db_prefix, $DB, $tablenum;
 
 $sql = str_replace("\r", "\n",$sql);
 $ret = array();
 $num = 0;
 foreach(explode(";\n", trim($sql)) as $query) {
  $queries = explode("\n", trim($query));
  foreach($queries as $query) {
   $ret[$num] .= $query[0] == '#' ? '' : $query;
  }
  $num++;
 }
 unset($sql);
 
 foreach($ret as $query) {
  $query = trim($query);
  if($query) {
   if(substr($query, 0, 12) == 'CREATE TABLE') {
    $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
    echo '创建表 '.$name.' ... <font color="#0000EE">------创建数据表成功!------</font><br />';
    mysql_query(createtable($query, $dbcharset));
    $tablenum++;
   } else {
    mysql_query($query);
   }
  }
 }
}
 
function createtable($sql, $dbcharset) {
 $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
 $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
 return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
  (mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
}
 
 
mysql_select_db($db_name);

runquery($sql);//导入数据文件

$sql = "INSERT INTO `ly` (`ly_id`, `head`, `name`, `qq`, `weixin`, `email`, `content`, `private`, `hf_content`, `modi_date`) VALUES
(1, 'head/001.gif', '测试留言', '', '', '', '测试留言', '0', '', '2019-02-11 12:48:23'),
(2, 'head/015.gif', '测试留言', '125184652', '15870685180', '562086760@qq.com', '测试留言', '1', '', '2019-02-12 13:55:36'),
(3, 'head/005.gif', '测试留言', '', '', '562086760@qq.com', '测试留言', '0', '', '2019-02-12 13:52:28');";
mysql_query($sql); 

$sql = "INSERT INTO `l_sys_info` (`sys_id`, `title`, `keywords`, `description`, `sys_note`) VALUES
(1,'辰颐物语小袁团队留言板v1.0','','','辰颐物语小袁团队留言板v1.0正式版开发完成，欢迎下载使用!'); ";
mysql_query($sql); 

$sql = "INSERT INTO `l_user` (`mg_id`, `user_name`, `user_pw`, `modi_date`) VALUES
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', '2019-02-09 13:33:45');";
mysql_query($sql); 

mysql_close($conn);

?>
<br><br>
-----------------------------------------------------------------------------------------------------------
<br><br>
<font color="#0000EE">------为安全考虑请删除install.php文件夹！------管理员帐号：admin 密码 admin</font>
<br/><br/>
<a href="../admin_login.php">管理员登陆</a>   
