我想在mysql中更新最后一个id,具体如何…:
$this->db->insert('mytable', $data);
$id = $this->db->insert_id();
然后$id是我的最后一个id,但我想在模型的更新函数中获得"最后一个id"。
您可以尝试在$id;上添加一个返回值;。在你的帖子中,你说你想获得最后一个更新id,但你必须插入。
更新时未测试,但插入时已测试。
型号
public function insert() {
$id = $this->db->insert_id() ;
$this->db->insert('mytable');
return $id;
}
public function addData($id, $data) {
$data = array(
'username' => $this->input->post('username')
);
$this->db->insert('anothertable', $data);
}
控制器
public function index() {
$this->load->model('yourmodel');
$id = $this->yourmodel->insert();
$this->yourmodel->addData($id, $this->input->post());
}