'2018-07-01 00:00:00' and create_at<='2018-08-15 00:00:00' and `is_coupon` =1 and `coupon_end_time` is null ; "; $stmt = $_PDO->prepare($sql); $stmt->execute(); $goods = $stmt->fetchAll(PDO::FETCH_ASSOC); $total_num = 0; $update_num = 0; foreach( $goods as $k=>$v ){ $total_num++; $keyword = KEYURL.$v['goods_id']; $result = TBK::search( $keyword ); if( !isset($result->coupon_end_time) ) continue; $coupon_end_time = $result->coupon_end_time; $coupon_start_time = $result->coupon_start_time; $sql = " update user_favorites set coupon_end_time = :coupon_end_time,coupon_start_time=:coupon_start_time where goods_id = :goods_id "; $stmt = $_PDO->prepare($sql); $stmt->execute(array(':coupon_end_time'=>$coupon_end_time,':coupon_start_time'=>$coupon_start_time,':goods_id'=>$v['goods_id'])); $res = $stmt->rowCount(); if($res){ var_dump($v['goods_id']); $update_num++; echo "\n更新成功:".$res; } //if($total_num == 3) break; } echo "\n总共".$total_num."条数据"; echo "\n成功更新".$update_num."条数据";