php实现批量分批次更新

php 实现批量,分批次更新
//更新最新的ThreeDayRrv数据
$sql = $sql_pre = "UPDATE coupon SET ThreeDayRev = CASE ID  ";
$i = 0;
$coupon_ids = array();
foreach ($coupon_rev as $value){
    $i++;
    $sql .= "WHEN {$value['CouponID']} THEN {$value['rev']} ";
    $coupon_ids[] = $value['CouponID'];
    
    if($i % 5000 == 0){
        $sql .= " END WHERE ID IN (".join(',',$coupon_ids).")";
        $www_db->query($sql);
        
        $coupon_ids = array();
        $sql = $sql_pre;
    }
}
if($sql != $sql_pre){
    $sql .= " END WHERE ID IN (".join(',',$coupon_ids).")";
    $www_db->query($sql);
}

你可能感兴趣的:(php实现批量分批次更新)