封裝sql語句中in限制查詢個數的方法


    /*  
     * 此方法用於每天凌晨取前一天的回滾用戶賬號
     */
    public function getRollBackAccount($startTime,$endTime){
        
        //1.首先查詢出當天的新增的用戶賬號    
        $sql_account = "SELECT DISTINCT `accountName`,`mTime` FROM `t_log_register` WHERE `mTime`>='{$startTime}' AND `mTime`<='{$endTime}'";
        $day_account = fetchRowSet($sql_account);

        foreach ($day_account as $key => $account) {
            $arr[] = $account['accountName'];    
           }

        // 統計回滾用戶的時間范圍限制兩個月內  
        //$two_months_before_time = strtotime(date("Y-m-d", strtotime("-2 month")));
        $now_end_time = $endTime-86400;
        // 批量查詢限制
        $count_account = count($arr);
        $base = 10;
        $group = floor($count_account / $base);
        for ($i=0; $i <= $group; $i++) { 
            echo  '<br>group: ' . $i . "<br>";
            $group_account = '';
            for ($j=0; $j < $base; $j++) { 
                $key = $i * $base + $j;
                if($key < $count_account) {
                    $group_account .= "'" . $arr[$key] . "',";
                }
            }
            $group_account = rtrim($group_account, ',');

            $sql_all_account = "SELECT DISTINCT `accountName`,`agentId`,`serverId`,`platform`,`mTime` FROM `t_log_register` WHERE `accountName` in ({$group_account}) AND `mTime` < '{$now_end_time}' ";
            $all_account = fetchRowSet($sql_all_account);    

               if(!empty($all_account)){
                  break;
               }     
        }
     
        $arr_account = array();
           foreach ($all_account as $key => $before_account) {
               $arr_account[$key]['agentId'] = $before_account['agentId'];
               $arr_account[$key]['serverId'] = $before_account['serverId'];
               $arr_account[$key]['platform'] = $before_account['platform'];
            $arr_account[$key]['accountName'] = $before_account['accountName'];
               $arr_account[$key]['mTime'] = $before_account['mTime'];    
           }
           return $arr_account;    
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM