【问题标题】:num_rows on delete query codeigniter [duplicate]删除查询codeigniter上的num_rows [重复]
【发布时间】:2016-09-27 12:27:04
【问题描述】:

我正在尝试找到一种方法来验证我的删除查询是否成功。如何从以下结构中获取 num_rows 或affected_rows:

public function fire_db($currentUserID, $id_staff){
        $this->db->where('id_player', $currentUserID);
        $this->db->where('id_hired_staff', $id_staff);
        $this->db->limit(1); 
        $this->db->delete('game_hired_staff'); 
        if ($this->db->num_rows() == 1) {
            return true; 
        }
        else
            return false;
    }

使用 codeigniter 3

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    测试删除查询使用的结果

    $this->db->affected_rows();
    

    【讨论】:

      【解决方案2】:

      这样试试

      public function fire_db($currentUserID, $id_staff){
          $this->db->where('id_player', $currentUserID);
          $this->db->where('id_hired_staff', $id_staff);
          $this->db->limit(1); 
      
          if (!$this->db->delete('game_hired_staff')) {
              return false;
          }
          else
              print_r($this->db->affected_rows());            
          }
      

      codeigniter db->delete() returns true always? 可能重复

      【讨论】:

        猜你喜欢
        • 2015-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-06
        • 2012-11-02
        • 2020-02-17
        相关资源
        最近更新 更多