如何使用CodeIgniter将表1的所有数据复制到表2,表1的主键除外。表1和表2具有相同的结构。
我尝试这样做:
$query = $this->db->get_where('table1',array('patient_id'=>$this->input->post('patient_id'))); foreach ($query->result() as $row) { $this->db->insert('table2',$row); }
它可以工作,但也插入了表1的主键。
如何忽略表1上的主键?
提前谢谢
假设患者ID是相关的主键,您可以使用 unset .
unset
$query = $this->db->get_where('table1',array('patient_id'=>$this->input->post('patient_id'))); foreach ($query->result() as $row) { unset($row->patient_id); $this->db->insert('table2',$row); }