0

有没有办法一次添加多条记录。通常我们称之为批量插入。目前我在做以下事情:

 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;
                }
    }
4

1 回答 1

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
于 2012-05-01T08:56:54.770 回答