免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1952 | 回复: 0
打印 上一主题 下一主题

[归档与迁移] phpbb迁移至newbb数据迁移程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-28 19:55 |只看该作者 |倒序浏览
// by balancesli
$db_server = "localhost"; // server name
$db_user = "db_user"; // username
$db_pass = "db_passwd"; // password
$phpbb_db = "db_src"; // phpbb database name
$phpbb_tbl = "phpbb_"; // table prefix
$xoops_db = "db_dst"; // xoop database name
$xoops_tbl = "xoops_"; // table prefix
$cat_ids_map = array();
$forum_ids_map = array();
$topic_ids_map = array();
if(!$dbh = mysql_connect($db_server, $db_user, $db_pass) )
{
printf("There was an error while connecting to the database! %s", mysql_error($dbh));
}
/* Copy Category */ // note: must use order by
$sql = sprintf("SELECT cat_id, cat_title, cat_order FROM %s.%scategories ORDER BY cat_id;",
$phpbb_db, $phpbb_tbl);
echo $sql."
\n";
$result = mysql_query($sql, $dbh);
while ($row = mysql_fetch_array($result))
{
$title = iconv("UTF-8", "GB2312", $row["cat_title"]);
$sql = sprintf(
"INSERT INTO %s.%sbb_categories(cat_title, cat_order)".
"VALUES('%s',%s);", $xoops_db, $xoops_tbl, $title, $row["cat_order"]
);
echo $sql."
\n";
if( !mysql_query($sql, $dbh) )
{
printf("There was an error while delting forum categories! %s", mysql_error($dbh));
}
$cat_ids_map[$row["cat_id"]] = mysql_insert_id($dbh);
}
foreach($cat_ids_map as $key => $cat_id)
{
echo $key."==>".$cat_ids_map[$key]."
\n";
}
/* Copy Forums */
$sql = sprintf(
"SELECT forum_id, cat_id, forum_name, forum_desc, forum_order, ".
"forum_topics, forum_posts, forum_last_post_id, forum_status ".
"FROM %s.%sforums ORDER BY forum_id;", $phpbb_db, $phpbb_tbl
);
echo $sql."
\n";
$result = mysql_query($sql, $dbh);
while ($row = mysql_fetch_array($result))
{
$forum_name = iconv("UTF-8", "GB2312", $row["forum_name"]);
$forum_desc = iconv("UTF-8", "GB2312", $row["forum_desc"]);
echo $row["cat_id"]."==>".$cat_ids_map[$row["cat_id"]]."
\n";
$cat_id = $cat_ids_map[$row["cat_id"]];
$sql = sprintf(
"INSERT INTO %s.%sbb_forums(cat_id, forum_name, forum_desc, forum_order, ".
"forum_topics, forum_posts, forum_last_post_id, forum_type) ".
"VALUES(%s,'%s','%s',%s, %s, %s, %s, %s);",
$xoops_db, $xoops_tbl, $cat_id, $forum_name,
$forum_desc, $row["forum_order"], $row["forum_topics"],
$row["forum_posts"], $row["forum_last_post_id"], $row["forum_status"]
);
echo $sql."
\n";
if( !mysql_query($sql, $dbh) )
{
printf("There was an error while delting forum categories! %s", mysql_error($dbh));
}
$forum_ids_map[$row["forum_id"]] = mysql_insert_id($dbh);
}
/* Copy Topics */
$sql = sprintf(
"SELECT topic_id, forum_id, topic_title, topic_poster, ".
"topic_time, topic_views, topic_replies, topic_last_post_id, ".
"topic_status, topic_type FROM %s.%stopics ORDER BY topic_id ;",
$phpbb_db, $phpbb_tbl
);
echo $sql."
\n";
$result = mysql_query($sql, $dbh);
while ($row = mysql_fetch_array($result))
{
$topic_title = iconv("UTF-8", "GB2312", $row["topic_title"]);
$forum_id = $forum_ids_map[$row["forum_id"]];
$sql = sprintf(
"INSERT INTO %s.%sbb_topics(".
"forum_id, topic_title, topic_poster, topic_time, ".
"topic_views, topic_replies, topic_last_post_id, topic_status, topic_sticky) ".
"VALUES(%s,'%s',%s, %s, %s, %s, %s, %s, %s);",
$xoops_db, $xoops_tbl, $forum_id, $topic_title,
$row["topic_poster"], $row["topic_time"],$row["topic_views"],
$row["topic_replies"], $row["topic_last_post_id"],$row["topic_status"],
$row["topic_type"]
);
echo $sql."
\n";
if( !mysql_query($sql, $dbh) )
{
printf("There was an error while delting forum categories! %s", mysql_error($dbh));
}
$topic_ids_map[$row["topic_id"]] = mysql_insert_id($dbh);
}
/* Copy Posts */
$sql = sprintf(
"SELECT p.post_id AS post_id, p.topic_id AS topic_id, p.forum_id AS forum_id, ".
"p.post_time AS post_time, p.poster_id AS poster_id, ".
"INET_ATON(CONCAT(CONV(MID(p.poster_ip,1,2), 16,10 ),'.',CONV(MID(p.poster_ip,3,2), 16,10 ),'.',CONV(MID(p.poster_ip,5,2), 16,10 ),'.',CONV(MID(p.poster_ip,7,2), 16,10 ))) AS poster_ip, ".
"t.post_subject AS post_subject, t.post_text AS post_text, p.enable_html AS enable_html, ".
"p.enable_smilies AS enable_smilies, p.enable_bbcode AS enable_bbcode, p.enable_sig AS enable_sig ".
"FROM %s.%sposts p ".
"LEFT JOIN %s.%sposts_text t ".
"ON p.post_id = t.post_id ORDER BY post_id; ",
$phpbb_db, $phpbb_tbl, $phpbb_db, $phpbb_tbl
);
echo $sql."
\n";
$result = mysql_query($sql, $dbh);
while ($row = mysql_fetch_array($result))
{
$post_subject = iconv("UTF-8", "GB2312",$row["post_subject"]);
$forum_id = $forum_ids_map[$row["forum_id"]];
$topic_id = $topic_ids_map[$row["topic_id"]];
$sql = sprintf(
"INSERT INTO %s.%sbb_posts(topic_id, forum_id, post_time, uid, ".
"poster_ip, subject, dohtml, dosmiley, doxcode, attachsig) ".
"VALUES(%s, %s, %s, %s, %s, '%s', %s, %s, %s, %s) ;",
$xoops_db, $xoops_tbl, $topic_id, $forum_id,
$row["post_time"],
$row["poster_id"],
$row["poster_ip"],
$post_subject,
$row["enable_html"],
$row["enable_smilies"],
$row["enable_bbcode"],
$row["enable_sig"]
);
echo $sql."
\n";
if( !mysql_query($sql, $dbh) )
{
printf("There was an error while adding posts! %s", mysql_error($dbh));
}
$new_post_id = @mysql_insert_id($dbh);
$post_text = iconv("UTF-8", "GB2312", $row["post_text"]);
$sql = sprintf(
"INSERT INTO %s.%sbb_posts_text(post_id, post_text) ".
"VALUES(%s, '%s');", $xoops_db, $xoops_tbl, $new_post_id, $post_text
);
if( !mysql_query($sql, $dbh) )
{
printf("There was an error while delting forum categories! %s", mysql_error($dbh));
}
}
mysql_close($dbh);
?>

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/74483/showart_1095000.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP