<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据导入到supesite5</title>
</head>
<body>
开始导入.............<br />
<?php
$dbhost = "localhost";
$dbuser = "mydb";
$dbpass = "mima";
$dbname = "dbname";
$target_link=mysql_connect($dbhost,$dbuser,$dbpass) or die ('Not connected : ' . mysql_error());
//mysql_select_db($dbname, $target_link) or die ('Can\'t use the current db : ' . mysql_error());
$mysql = "select * from $dbname.news_message where type =1 and id >0 and id<3 order by id";
$result = mysql_query($mysql, $target_link);
while ($r = mysql_fetch_array($result))
{
$target_db = 'chinarbs';
$catid =1 ; //资讯类别 1 国内新闻 2国外动态 3热点观察
$uid=1;
$tid = 0; // 对应论坛主题 id
$username = 'chao';
$itemtypeid = 0; // 个人分类ID
$type='news'; //属于资讯大类
$subtype = ''; // 信息分类型
$subject = $r[title] ; //信息标题
$dateline = $r[posttime]; //UNIX时间戳 mysql> select UNIX_TIMESTAMP('2007-6-9 12:55:50'); 1181364950
$lastpost = $dateline; //最后回复时间
$viewnum = $r[hit]; // 点击次数
$replynum=0;
$trackbacknum = 0; // Trackback 数
$goodrate = 0;
$badrate = 0;
$digest = 0;
$top = 0;
$allowreply = 1;
$folder = 1;
$haveattach = 0;
$grade = 0;
$query_insert = mb_convert_encoding("INSERT INTO {$target_db}.supe_spaceitems (`catid`, `uid`, `tid`, `username`, `itemtypeid`, `type`, `subtype`, `subject`, `dateline`, `lastpost`, `viewnum`, `replynum`, `trackbacknum`, `goodrate`, `badrate`, `digest`, `top`, `allowreply`, `folder`, `haveattach`, `grade`) VALUES('$catid', '$uid', '$tid', '$username', '$itemtypeid', '$type', '$subtype', '$subject', UNIX_TIMESTAMP('$dateline'), UNIX_TIMESTAMP('$lastpost'), '$viewnum', '$replynum', '$trackbacknum', '$goodrate', '$badrate', '$digest', '$top', '$allowreply', '$folder', '$haveattach', '$grade');", "utf-8", "gb2312");
//print_r ($query_insert);
//echo "<br>";
mysql_query("set names utf8;");
mysql_query($query_insert,$target_link);
$itemid = mysql_insert_id($target_link);
$hash = substr(md5($itemid), 8, 16); // 表单关联
$query_update = "update {$target_db}.supe_spaceitems set hash='$hash' where itemid=$itemid;";
//$query_update = "update {$target_db}.supe_spaceitems set hash=substr(md5(LAST_INSERT_ID()), 8, 16) where itemid>5;";
echo $itemid ;
echo "<br>";
$query_insert = mb_convert_encoding("INSERT INTO {$target_db}.supe_spacenews (`itemid`,`message`) VALUES ($itemid,'$r[info]');", "utf-8", "gb2312");;
print_r ($query_insert);
echo "<br>";
mysql_query("set names utf8;");
mysql_query($query_insert,$target_link);
}
mysql_close();
?>
<br />
导入结束 ..........
</body>
</html>