gpt4 book ai didi

php - 如何在 codeigniter 中获取更新的 id

转载 作者:行者123 更新时间:2023-11-29 01:13:05 25 4
gpt4 key购买 nike

我是 Codeigniter 的新手,但从网络上学习,实际上我遇到了一个未知问题。

我将数据插入数据库抛出模型,然后将数据取回表单。

但是当我更新表单时,我想返回更新后的 ID。

我使用了 $user_id = $this->db->insert_id(); 但这是为了获取插入 ID,

连我都试过了

 $this->db->where('id_colum', $student_id);
$this->db->update('table_name', $data);
$user_id = $this->db->insert_id();
return $user_id;

帮帮我,感谢一切..

最佳答案

就像这样:

$this->db->where('id_colum', $student_id);
$this->db->update('table_name', $data);
$updated_status = $this->db->affected_rows();

if($updated_status):
return $student_id;
else:
return false;
endif;

如果已更新,则返回 $student_id。 :)

关于php - 如何在 codeigniter 中获取更新的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33330748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com