有没有办法一次添加多个记录。通常我们称之为批量插入。 目前我正在做以下事情:
foreach ($datalist as $data)
try {
$this->template_id = $data['template_id'];
$this->notifier_id = $data['notifier_id'];
$this->user_id = $data['user_id'];
$this->date_created= date('Y-m-d h:i:s');
$this->save();
return true;
} catch (Kohana_Exception $e) {
return false;
}
}
答案 0 :(得分:7)
$query = DB::insert('company_schedule', array('day', 'work_start', 'work_end', 'week_start', 'week_end', 'company_id')); // create sql request
$query->values(array(
$key, $work_start, $work_end, $week_start, $week_end, $this->id
)); // do it in loop
$query->execute(); // execute