2012-04-30 184 views
0

有沒有辦法一次添加多個記錄?通常我們稱之爲批量插入。 目前我做了以下內容:kohana批量插入

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

什麼是你的問題? – egis

+0

我想運行插入循環 –

+0

你使用kohana orm模塊嗎? – egis

回答

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