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

简介: $where = ''; $localogLogin = $this->gamedb_model->query_onerow("select `datetime` from logLogin order by id desc"); $posda...
$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++;
                    }
            }

 

目录
相关文章
|
3月前
|
JSON 数据处理 PHP
PHP数组处理技巧:高效操作数据集合
PHP数组处理技巧:高效操作数据集合
|
3月前
|
JSON 安全 大数据
PHP中的数组处理艺术:灵活高效的数据操作
PHP中的数组处理艺术:灵活高效的数据操作
|
3月前
|
JSON 定位技术 PHP
PHP技巧:解析JSON及提取数据
这就是在PHP世界里探索JSON数据的艺术。这场狩猎不仅仅是为了获得数据,而是一种透彻理解数据结构的行动,让数据在你的编码海洋中畅游。通过这次冒险,你已经掌握了打开数据宝箱的钥匙。紧握它,让你在编程世界中随心所欲地航行。
143 67
|
6月前
|
数据库连接 PHP 数据库
【YashanDB知识库】PHP使用ODBC驱动无法获取长度为256char以上的数据
【YashanDB知识库】PHP使用ODBC驱动无法获取长度为256char以上的数据
|
6月前
|
Oracle 关系型数据库 MySQL
【YashanDB知识库】php查询超过256长度字符串,数据被截断的问题
本文分析了YashanDB中PHP通过ODBC查询数据时出现的数据截断问题,表现为超过256字节的数据被截断,以及isql工具无法显示超过300字节长度的数据。问题根源在于YashanDB的ODBC驱动仅支持单次查询,且PHP扩展库默认缓冲区限制。解决方案包括改用PHP ODBC扩展库而非PDO_ODBC,以及调整isql代码逻辑以支持循环取数或一次性读取完整数据。文章还提供了具体代码示例和规避方法,适用于23.2.4.14及更早版本。
【YashanDB知识库】php查询超过256长度字符串,数据被截断的问题
|
7月前
|
Oracle 关系型数据库 MySQL
【YashanDB 知识库】php 查询超过 256 长度字符串,数据被截断的问题
php 查询超过 256 字节数据,显示被截断:yashandb 的 odbc 驱动接口 SQLGetData 现在只支持单次查询,不支持多次取数据的操作。 isql 显示不出来,isql 工具最大只查询 300 长度的数据,超过了该长度未正常显示。
|
10月前
|
数据采集 JSON JavaScript
如何通过PHP爬虫模拟表单提交,抓取隐藏数据
本文介绍了如何使用PHP模拟表单提交并结合代理IP技术抓取京东商品的实时名称和价格,特别是在电商大促期间的数据采集需求。通过cURL发送POST请求,设置User-Agent和Cookie,使用代理IP绕过限制,解析返回数据,展示了完整代码示例。
207 3
如何通过PHP爬虫模拟表单提交,抓取隐藏数据
|
12月前
|
设计模式 SQL 安全
PHP中的设计模式:单例模式的深入探索与实践在PHP的编程实践中,设计模式是解决常见软件设计问题的最佳实践。单例模式作为设计模式中的一种,确保一个类只有一个实例,并提供全局访问点,广泛应用于配置管理、日志记录和测试框架等场景。本文将深入探讨单例模式的原理、实现方式及其在PHP中的应用,帮助开发者更好地理解和运用这一设计模式。
在PHP开发中,单例模式通过确保类仅有一个实例并提供一个全局访问点,有效管理和访问共享资源。本文详细介绍了单例模式的概念、PHP实现方式及应用场景,并通过具体代码示例展示如何在PHP中实现单例模式以及如何在实际项目中正确使用它来优化代码结构和性能。
156 2
PHP中为什么静态类是不能被实例化的类?底层原理是什么?
PHP中为什么静态类是不能被实例化的类?底层原理是什么?
155 0
|
程序员 PHP
PHP的ReflectionClass类是干什么的?底层原理是什么?
PHP的ReflectionClass类是干什么的?底层原理是什么?
305 0