DedeCms批量写入数据的函数 – DeDecms


avatar
pcwnas 2023-04-21 150

原文来自:https://www.zixuephp.com

DedeCms批量写入数据的函数

dedecms如果是新闻与软件表我们只要操作三个表就可以了,如果我们要对批量插入的数据设置未设置状态只要在主表字段arcrank设置为-1就可以,下面看一个例子,代码如下:

  1. //本类由系统自动生成,仅供测试用途
  2. classIndexActionextendsAction{
  3. publicfunctionindex(){
  4. $id=$this->_get('id');$endid=$this->_get('endid');
  5. $typeid=9;//写入的栏目
  6. $db=M();if(!$id||!$endid){
  7. $listend=$db->table('dede_archives')->limit(1)->order('iddesc')->find();
  8. exit('noidandendididmuststartbigfrom'.$listend['id']);//必须大于某id开始
  9. }
  10. $list=$db->table('tb1')->where('status=0')->find();//查找待发布DB未发布的
  11. if($list){
  12. $time=time();
  13. $r1=$db->query("INSERTINTO`dede_arctiny`VALUES(".$id.",".$typeid.",'0',0,1,".$time.",".$time.",1)");//写入到织梦DB
  14. $data2['arcrank']=-1;
  15. $data2['title']=$list['title'];
  16. $data2['typeid']=$typeid;
  17. $data2['id']=$id;$data2['pubdate']=$time;
  18. $data2['senddate']=$time;$data2['sortrank']=$time;
  19. $data2['mid']=1;
  20. $data2['dutyadmin']=1;
  21. $data2['weight']=1;
  22. $r2=$db->table('dede_archives')->add($data2);
  23. if($r2>0){//写入成功后写入附加表
  24. $r3=$db->query('INSERTINTO`dede_addonarticle`VALUES('.$id.','.$typeid.',"'.$list['content'].'","","","127.0.0.1")');
  25. $r4=$db->table('tb1')->where("id=".$list['id'])->setField('status',1);//写入成功后标记为已发布
  26. if($r4){
  27. $nextid=$id+1;
  28. //$this->redirect("index",array('id'=>$nextid));//if($id=99999||$id=88888)exit;
  29. echo'ok'.$id;
  30. echo'next'.$nextid;if($endid==$id)exit('<br>theendid!');
  31. echo"<script>window.location.href='/Sphp/index.php?s=/Index/index/id/".$nextid."/endid/".$endid."'</script>";
  32. }
  33. }
  34. //dump($r2);
  35. //dump($r3);
  36. exit;
  37. }else{echo'noarticleyet';}
  38. }
  39. }