php 批量导入昨天的数据(别类版的增量备份安案)

$where = '';
            $localogLogin = $this->gamedb_model->query_onerow("select `datetime` from logLogin order by id desc");
            $posdatetime =     $localogLogin['datetime'];
            if(empty()){
                $where = "where datetime<'$todaydate'";
            }else{
                $where = "where datetime<'$todaydate' and datetime>'$posdatetime'";
            }
            $remountlist = $this->remotedb_model->query_onerow("select count(*) as num from logLogin $where");
            $allcount = $remountlist['num'];
            if($allcount){
                $page = 1;//当前页
                $pagesize=1000;//分页大小
                $failt = 0;// 失败次数
                $allpage =ceil($allcount/$pagesize);//分页总大小
                while($page <= $allpage){
                        $sqltmp = 'insert  into `loglogin`(`accid`,`roleID`,`macAddr`,`ip`,`datetime`,`online`) values';
                        //一天一天的算
                        $templogdate = $this->remotedb_model->query_lists("select * from logLogin $where order by datetime asc limit ".($page-1)*$pagesize.",$pagesize");
                        foreach ($templogdate as $k => $val) {
                                $tempdate = substr($val['datetime'],0,strpos($val['datetime']," "));
                                if($k == (count($templogdate)-1)){
                                    $sqltmp .="($val[accid],$val[roleID],'$val[macAddr]','$val[ip]','$val[datetime]',$tempdate)";
                                }else{
                                    $sqltmp .="($val[accid],$val[roleID],'$val[macAddr]','$val[ip]','$val[datetime]',$tempdate),";
                                }
                        }
                        $this->gamedb_model->query($sqltmp);
                        $sqltmp = '';
                        $page++;
                    }
            }

 

$localogLogin = $this->gamedb_model->query_onerow("select id from logLogin order by id desc");
            $maxid = empty($localogLogin['id'])?'0':$localogLogin['id'];
            $remountlist = $this->remotedb_model->query_onerow("select count(*) as num from logLogin where id>$maxid");                
            $allcount = $remountlist['num'];
            if($allcount){
                $page = 1;//当前页
                $pagesize=1000;//分页大小
                $failt = 0;// 失败次数
                $allpage =ceil($allcount/$pagesize);//分页总大小
                while($page <= $allpage){
                        $sqltmp = 'insert  into `loglogin`(`accid`,`roleID`,`macAddr`,`ip`,`datetime`,`online`) values';
                        //一天一天的算
                        $templogdate = $this->remotedb_model->query_lists("select * from logLogin where id>$maxid order by id asc limit ".($page-1)*$pagesize.",$pagesize");
                        foreach ($templogdate as $k => $val) {
                            
                                $tempdate = substr($val['datetime'],0,strpos($val['datetime']," "));
                                
                                if($k == (count($templogdate)-1)){
                                    $sqltmp .="($val[accid],$val[roleID],'$val[macAddr]','$val[ip]','$val[datetime]',$tempdate)";
                                }else{
                                    $sqltmp .="($val[accid],$val[roleID],'$val[macAddr]','$val[ip]','$val[datetime]',$tempdate),";
                                }
                        }

                        $this->gamedb_model->query($sqltmp);
                        $sqltmp = '';
                        $page++;
                    }
            }

 

posted @ 2013-10-22 21:01  jackluo  阅读(542)  评论(0编辑  收藏  举报