先登录畅言,然后导出评论数据,json格式的。如果数据量大,就分时间段导出。
下面的代码,把这个json数据,读到帝国cms评论表中:
中间有过出错,是因为content没有addaslashes,所以导致导入帝国的评论表有重复的数据。可好,最近完成了帝国批量王的单表操作,删除重复的,正好拿来练手,代码如下:
- <?php
- require('../class/connect.php');
- require('../class/db_sql.php');
- require('../data/dbcache/class.php');
- require('../member/class/user.php');
- require('../data/dbcache/MemberLevel.php');
- require LoadLang('pub/fun.php');
- $link=db_connect();
- $empire=new mysqlquery();
- $myr=file_get_contents('changyan.json');
- $myr=json_decode($myr,true);
- set_time_limit(1000);
- foreach($myr[comments] as $v){
- $r=array();
- $r[username]=$v[nickname];
- $r[sayip]=$v[ip];
- $r[saytime]=strtotime($v[ctime]);
- $r[id]=$v[topicSourceId];
- if(!$r[id])continue;
- $r[classid]=$empire->gettotal("select classid as total from {$dbtbpre}ecms_news where id={$r[id]} limit 1");
- $r[pubid]=ReturnInfoPubid($r[classid],$r[id]);
- $r[saytext]=addslashes($v[content]);
- $r[sayip]=$v[ip];
- $empire->query("insert into {$dbtbpre}enewspl_1 set ".r2sql($r));
- }
- echo 'ok!';
- db_close();
- $empire=null;
- function r2sql($r){
- $yqpl='';
- foreach($r as $key=>$value){if(!is_numeric($key))$yqpl.=$key."='".$value."',";}
- return rtrim($yqpl,',');
- }
- $empire->query("delete from {$dbtbpre}enewspl_1 where plid<>'$r[plid]' and id='$r[id]' and saytime='$r[saytime]'");