本文實(shí)例分析了DedeCms批量寫入數(shù)據(jù)的函數(shù)。分享給大家供大家參考。具體分析如下:
dedecms如果是新聞與軟件表我們只要操作三個(gè)表就可以了,如果我們要對批量插入的數(shù)據(jù)設(shè)置未設(shè)置狀態(tài)只要在主表字段arcrank設(shè)置為-1就可以,下面看一個(gè)例子,代碼如下:
復(fù)制代碼代碼如下:// 本類由系統(tǒng)自動生成,僅供測試用途
class IndexAction extends Action {
public function index(){
$id = $this->_get('id');
$endid = $this->_get('endid');
$typeid = 9;//寫入的欄目
$db = M();
if(!$id || !$endid){
$listend = $db->table('dede_archives')->limit(1)->order('id desc')->find();
exit('no id and endid id must start big from '.$listend['id']); //必須大于某id開始
}
$list = $db->table('tb1')->where('status=0')->find();//查找待發(fā)布DB未發(fā)布的
if($list){
$time=time();
$r1= $db->query("INSERT INTO `dede_arctiny` VALUES(".$id.", ".$typeid.", '0', 0, 1, ".$time.", ".$time.", 1)");//寫入到織夢DB
$data2['arcrank']=-1;
$data2['title']=$list['title'];
$data2['typeid']=$typeid;
$data2['id']=$id;
$data2['pubdate']=$time;
$data2['senddate']=$time; $data2['sortrank']=$time;
$data2['mid']=1;
$data2['dutyadmin']=1;
$data2['weight']=1;
$r2=$db->table('dede_archives')->add($data2);
if($r2>0){//寫入成功后寫入附加表
$r3= $db->query('INSERT INTO `dede_addonarticle` VALUES('.$id.', '.$typeid.', "'.$list['content'].'", "", "", "127.0.0.1")');
$r4 = $db->table('tb1')->where("id = ".$list['id'])->setField('status',1);//寫入成功后標(biāo)記為已發(fā)布
if($r4){
$nextid = $id+1;
//$this->redirect("index",array('id'=>$nextid)); //if($id=99999 || $id=88888) exit;
echo 'ok '.$id;
echo 'next '.$nextid; if($endid==$id) exit('
the end id!');
echo"<script>window.location.href='/Sphp/index.php?s=/Index/index/id/".$nextid."/endid/".$endid."'</script>";
}
}
//dump($r2);
//dump($r3);
exit;
}else{
echo 'no article yet';
}
}
}
希望本文所述對大家的dedecms建站有所幫助。
更多信息請查看IT技術(shù)專欄