php – Codegniter – Internal error when acessing database-ThrowExceptions

Exception or error:

I’m using CodeIgniter to access the database, but everytime I run the code it gets an internal error. This is my jQuery code:

function showCadeiras() {
  $.ajax({
    type: "POST",
    url: base_url + "api/teacher/getCadeiras",
    data: {id: localStorage.user_id},
    success: function(data) {
        for(var i = 0; i < data.cadeiras_id.length; i++) {
            var cadeira_id = data.cadeiras_id[i].cadeira_id;
            $.ajax({
                type: "POST",
                url: base_url + "api/teacher/getCadeiraInfo",
                data: {id: cadeira_id},
                success: function(data) {
                    console.log(data);
                },
                error: function(data) {
                    console.log("error");
                }
            })
        }
    },
    error: function(data) {
        console.log(data);
    }
  });
}

Here is the code inside the Controller:

    public function getCadeiras() {
       $user_id = $this->post('id');
       $this->load->model('UserModel');
       $data["cadeiras_id"] = $this->UserModel->getCadeiras($user_id);

       $this->response($data, parent::HTTP_OK);
   }

   public function getCadeiraInfo(){
      $cadeira_id = $this->post('cadeira_id');
      $this->load->model('UserModel');
      $data["info"] = $this->UserModel->getCadeiraInfo($cadeira_id);

      $this->response($data, parent::HTTP_OK)
   }

Lastly, the Model code:

    public function getCadeiras($id) {
       $this->db->select("cadeira_id");
       $this->db->where(array('user_id =' => $id));
       $query = $this->db->get('professor_cadeira');
       return $query->result_array();
   }

   public function getCadeiraInfo($id) {
       $query = $this->db->get_where('cadeira', array('id =' => $id));
       return $query->result_array();
   }

Everytime I comment the second function (getCadeiraInfo) the code works without a problem, however it doesn’t work with the second function. They are written in a similar way, I don’t understand the error.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *