gpt4 book ai didi

php - 在 Codeigniter 中查找数据库中实际删除或未删除的数据的方法

转载 作者:行者123 更新时间:2023-11-30 00:09:27 25 4
gpt4 key购买 nike

大家好,有什么方法可以检查 codeigniter 中的数据是否确实从数据库中删除了?我有一种方法可以从我的模型中的数据库中删除数据

             $this->db->delete('product', array('category' => $id)); 

我已经在我的 Controller 中设置了闪存数据数据库中的数据不会被删除,但会显示闪存消息。

我只需要在从数据库中实际删除时显示闪存数据。

最佳答案

我更喜欢这个

在模型中,例如称为“产品”

function deleteProductBy( $id ) {
$this->db->where( 'category', $id );
$this->db->delete( 'product' );

if ( $this->db->affected_rows() == '1' ) {return TRUE;}
else {return FALSE;}

}

在 Controller 中

  if( $this->products->deleteProductBy($id) == false ){

// fail message is sad
}
else{
// success message is happy
}

因此,模型中的删除方法只需返回 true 或 false - 然后在 Controller 中您决定如何显示结果。然后,当显示结果的方式发生变化时,模型中的删除方法保持不变。当我胡言乱语时,我的建议是首先检查是否存在错误情况。

关于php - 在 Codeigniter 中查找数据库中实际删除或未删除的数据的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24204514/

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