gpt4 book ai didi

mysql - 使用 join codeigniter 同时删除两个 mysql 表

转载 作者:行者123 更新时间:2023-11-29 15:35:53 24 4
gpt4 key购买 nike

我试图使用此函数一次从两个 mysql 表中删除。

public function deleteBusiness($id)
{
$this->db->from("business");
$this->db->join("opening_hours", "business");
$this->db->where("business", $id);
return $this->db->delete(array("business","opening_hours"));
}

它似乎工作正常,因为正确的数据正在从两个表中删除,但是当我用以下命令调用它时......

if($this->businesses_model->deleteBusiness($id)){
$this->session->set_flashdata('flash_message', 'Business Deleted');
} else {
$this->session->set_flashdata('flash_message', 'There was a problem deleting that business');
}

正在显示失败的错误消息。

最佳答案

将上面的代码替换为以下代码,如果不起作用请告诉我

public function deleteBusiness($id)
{
$this->db->from("business");
$this->db->join("opening_hours", "business");
$this->db->where("business", $id);
$this->db->delete(array("business","opening_hours"));
return $this->db->affected_rows();
}


if($this->businesses_model->deleteBusiness($id) > 0){
$this->session->set_flashdata('flash_message', 'Business Deleted');
} else {
$this->session->set_flashdata('flash_message', 'There was a problem deleting that business');
}

如果不起作用请告诉我

关于mysql - 使用 join codeigniter 同时删除两个 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58243427/

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