我的行动
if(Yii::$app->request->post()){
$eventName = Event::find()->select(['Event_name'])->from('Event')->where(['Calendar' => ['4']])->all();
$model->file = $model->uploadFile($model,'file');
$fh = fopen($_FILES['uploadfile']['tmp_name'], "r");
while (($row = fgetcsv($fh, 0, ","))!= FALSE)
{
$model = new Event();
$model->Event_name = $row[0];
$model->Discription = $row[1];
foreach ($eventName as $value){
if($value->Event_name != $model->Event_name){
$model->save();
}
}
}
}
}
return $this->render('index', ['model' => $model,'value'=> $query]);
我想检查我的db(mongodb)和csv文件中的重复记录。 if condition true model将数据保存到db 否则删除旧数据并将新数据保存到db