是我不小心 發表於 2024-3-7 00:00:00

DedeCms批量写入数据的函数分析

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        本文实例分析了DedeCms批量写入数据的函数。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        dedecms如果是新闻与软件表我们只要操作三个表就可以了,如果我们要对批量插入的数据设置未设置状态只要在主表字段arcrank设置为-1就可以,下面看一个例子,代码如下:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        // 本类由系统自动生成,仅供测试用途 <br>
        class IndexAction extends Action { <br>
        public function index(){ <br>
        $id = $this-&gt;_get('id');<br>
        $endid = $this-&gt;_get('endid'); <br>
        $typeid = 9;//写入的栏目 <br>
        $db = M();<br>
        if(!$id || !$endid){ <br>
        $listend = $db-&gt;table('dede_archives')-&gt;limit(1)-&gt;order('id desc')-&gt;find(); <br>
        exit('no id and endid id must start big from '.$listend['id']); //必须大于某id开始 <br>
        } <br>
        $list = $db-&gt;table('tb1')-&gt;where('status=0')-&gt;find();//查找待发布DB未发布的 <br>
        if($list){ <br>
        $time=time(); <br>
        $r1= $db-&gt;query("INSERT INTO `dede_arctiny` VALUES(".$id.", ".$typeid.", '0', 0, 1, ".$time.", ".$time.", 1)");//写入到织梦DB <br>
        $data2['arcrank']=-1; <br>
        $data2['title']=$list['title']; <br>
        $data2['typeid']=$typeid; <br>
        $data2['id']=$id;<br>
        $data2['pubdate']=$time; <br>
        $data2['senddate']=$time; $data2['sortrank']=$time; <br>
        $data2['mid']=1; <br>
        $data2['dutyadmin']=1; <br>
        $data2['weight']=1; <br>
        $r2=$db-&gt;table('dede_archives')-&gt;add($data2); <br>
        if($r2&gt;0){//写入成功后写入附加表 <br>
        $r3= $db-&gt;query('INSERT INTO `dede_addonarticle` VALUES('.$id.', '.$typeid.', "'.$list['content'].'", "", "", "127.0.0.1")'); <br>
        $r4 = $db-&gt;table('tb1')-&gt;where("id = ".$list['id'])-&gt;setField('status',1);//写入成功后标记为已发布 <br>
        if($r4){ <br>
        $nextid = $id+1; <br>
        //$this-&gt;redirect("index",array('id'=&gt;$nextid)); //if($id=99999 || $id=88888) exit; <br>
        echo 'ok '.$id; <br>
        echo 'next '.$nextid; if($endid==$id) exit('<br>
        the end id!'); <br>
        echo""; <br>
        } <br>
        } <br>
        //dump($r2); <br>
        //dump($r3); <br>
        exit; <br>
        }else{<br>
        echo 'no article yet';<br>
        } <br>
        } <br>
        }</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: DedeCms批量写入数据的函数分析