$this->db->trans_start();
foreach($batches as $batch)//$batches数组有10000多条记录
{
$this->db->where('id'=>$batch->id)->from('table');
$count = $this->db->count_all_results();
if($count > 0)
{
$this->db->update($batch)->where('id'=>$batch->id);//如果记录存在则更新
}else
{
$this->db->insert('table', $batch);//如果不存在就插入新纪录
}
}
$this->db->trans_complete();