esa*_*wan 2 php mysql codeigniter lastinsertid
在我的表单中,有值要插入到多个表中.插入第一个表后,我必须插入其他值,以及第一个表的条目的"id"作为参考.做这个的最好方式是什么?有没有codeigniter特定的方式?
$this->db->insert_id()可能就是你要找的东西.以下是它如何工作的示例:
$this->db->insert('Table1',$values);
$table1_id=$this->db->insert_id();
$otherValues=array(
'table1_id'=>$table1_id,
);
$this->db->insert('otherTable',$otherValues);
Run Code Online (Sandbox Code Playgroud)