sablog到wordpress数据转换
时间:2008-12-06
来源:互联网
今天把博客换成wp了,简单写了个代码把日志和评论转了过去
[php]
<?php
/**
* SABLOG-X v1.6 转 WordPress 2.6.5
* author: Linvo
* date: 2008-12-6
* 注意:
* 1、只转换日志和评论数据
* 2、两者数据表在同一库中
*/
header('Content-Type:text/html;Charset=utf-8;');
date_default_timezone_set("PRC");
$DBaddress = 'localhost'; //服务器
$DBusername = 'root'; //mysql用户名
$DBpassword = 'pwd'; //mysql密码
$DBname = 'dbname'; //数据库名
mysql_connect($DBaddress, $DBusername, $DBpassword);
mysql_query('set names utf8');
mysql_select_db($DBname);
/*
* 添加日志
*/
$error = '';
$sql_from = 'SELECT articleid,uid,dateline,content,title,description,comments
FROM sablog_articles';
$result = mysql_query($sql_from);
while($item = mysql_fetch_row($result))
{
$item[2] = date('Y-m-d H:i:s', $item[2]);
$item[3] = addslashes($item[3]);
$item[5] = addslashes($item[5]);
$sql_to = "INSERT INTO wp_posts(ID,post_author,post_date,post_content,
post_title,post_excerpt,comment_count)
VALUE('$item[0]','$item[1]','$item[2]','$item[3]','$item[4]','$item[5]','$item[6]')";
mysql_query($sql_to);
if(mysql_affected_rows() != 1) $error .= "日志转换出错,出错ID:$item[0] <br />";
}
if(empty($error)) echo '日志转换完毕!<br />';
else echo $error;
/*
* 添加评论
*/
$error = '';
$sql_from = 'SELECT commentid,articleid,author,url,ipaddress,dateline,content
FROM sablog_comments';
$result = mysql_query($sql_from);
while($item = mysql_fetch_row($result))
{
$item[5] = date('Y-m-d H:i:s', $item[5]);
$item[6] = addslashes($item[6]);
$sql_to = "INSERT INTO wp_comments(comment_ID,comment_post_ID,comment_author,
comment_author_url,comment_author_IP,comment_date,comment_content)
VALUE('$item[0]','$item[1]','$item[2]','$item[3]','$item[4]','$item[5]','$item[6]')";
mysql_query($sql_to);
if(mysql_affected_rows() != 1) $error .= "评论转换出错,出错ID:$item[0] <br />";
}
if(empty($error)) echo '评论转换完毕!<br />';
else echo $error;
?>
[/php]
[php]
<?php
/**
* SABLOG-X v1.6 转 WordPress 2.6.5
* author: Linvo
* date: 2008-12-6
* 注意:
* 1、只转换日志和评论数据
* 2、两者数据表在同一库中
*/
header('Content-Type:text/html;Charset=utf-8;');
date_default_timezone_set("PRC");
$DBaddress = 'localhost'; //服务器
$DBusername = 'root'; //mysql用户名
$DBpassword = 'pwd'; //mysql密码
$DBname = 'dbname'; //数据库名
mysql_connect($DBaddress, $DBusername, $DBpassword);
mysql_query('set names utf8');
mysql_select_db($DBname);
/*
* 添加日志
*/
$error = '';
$sql_from = 'SELECT articleid,uid,dateline,content,title,description,comments
FROM sablog_articles';
$result = mysql_query($sql_from);
while($item = mysql_fetch_row($result))
{
$item[2] = date('Y-m-d H:i:s', $item[2]);
$item[3] = addslashes($item[3]);
$item[5] = addslashes($item[5]);
$sql_to = "INSERT INTO wp_posts(ID,post_author,post_date,post_content,
post_title,post_excerpt,comment_count)
VALUE('$item[0]','$item[1]','$item[2]','$item[3]','$item[4]','$item[5]','$item[6]')";
mysql_query($sql_to);
if(mysql_affected_rows() != 1) $error .= "日志转换出错,出错ID:$item[0] <br />";
}
if(empty($error)) echo '日志转换完毕!<br />';
else echo $error;
/*
* 添加评论
*/
$error = '';
$sql_from = 'SELECT commentid,articleid,author,url,ipaddress,dateline,content
FROM sablog_comments';
$result = mysql_query($sql_from);
while($item = mysql_fetch_row($result))
{
$item[5] = date('Y-m-d H:i:s', $item[5]);
$item[6] = addslashes($item[6]);
$sql_to = "INSERT INTO wp_comments(comment_ID,comment_post_ID,comment_author,
comment_author_url,comment_author_IP,comment_date,comment_content)
VALUE('$item[0]','$item[1]','$item[2]','$item[3]','$item[4]','$item[5]','$item[6]')";
mysql_query($sql_to);
if(mysql_affected_rows() != 1) $error .= "评论转换出错,出错ID:$item[0] <br />";
}
if(empty($error)) echo '评论转换完毕!<br />';
else echo $error;
?>
[/php]
作者: linvo 发布时间: 2008-12-06
不错 :)辛苦
作者: 0hudu 发布时间: 2008-12-06
辛苦楼主了!
作者: abcnic 发布时间: 2008-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28