使用codeigniter的存储过程

时间:2019-02-20 04:33:57

标签: codeigniter

我在使用存储过程在CodeIgniter中进行更新和删除时遇到问题。我在模型中有以下代码

public function getuser($users_id)
{
    $get_user_stored_proc = "CALL get_user(?,?)";
    $query = $this->db->get_where($get_user_stored_proc, array('users_id' => $users_id));
    return $query->row_array();
}

public function update_user($user, $users_id)
{
    $update_user_stored_proc = "CALL update_user(?,?)";
    $this->db->where($update_user_stored_proc, $users_id;
    return $this->db->update('users', $user);
}

public function delete_user($users_id)
{
    $delete_user_stored_proc = "CALL delete_user(?,?)";
    $result = $this->db->where($delete_user_stored_proc, $users_id);
    if ($result !== null) {
        return true;
    }
    return false;
}

我遇到以下错误enter image description here

2 个答案:

答案 0 :(得分:0)

仅当他期望两个值时,您才给存储过程赋值。 在您提供的屏幕截图中,我们只能在查询中看到用户ID(6)。

答案 1 :(得分:0)

For Delete user:
    **Controller page:**
    public function delete_user(){
            $uri_id=$this->uri->segment(4,0);
            $this->load->database();
            $this->load->model('Home_model');
            $this->Home_model->delete_user($uri_id);
            redirect('controller_name/viewuserlist','refresh');
        }
    // uri_id is the id you send through the url of the page 
    **Model page:**
    function delete_user($user_id){
          $this->db->where('user_id',$user_id);
          return $this->db->delete('table_name');
        }