Welcome Guest, Not a member yet? Register   Sign In
Database query conflict
#1

Hello,

I'm quite new to CodeIgniter and I'm having some kind of a weird issue while trying to execute consecutively two queries from the same model in my controller.

Here is the code of the controller and the model :

Controller: Login
PHP Code:
public function connection() {
 
       $data = array();
 
       $data['title_header'] = "Connexion";

 
       $this->form_validation->set_rules('mail''Adresse email''trim|required|valid_email');
 
       $this->form_validation->set_rules('password''Mot de passe''trim|required|min_length[6]');
 
       if($this->form_validation->run() == false){
 
           $this->load->template('Login_view'$data);
 
       } else {
 
           $mail $this->input->post('mail');
 
           $password $this->input->post('password');
 
           $storedPassword $this->login->check_user_credentials($mail);

 
           if ($this->compare_password($password$storedPassword->password)) {
 
               $userInfo $this->login->get_user_info($mail);

 
               print_r($userInfo);

 
               $userId $userInfo->id_utilisateur;
 
               $userOK $userInfo->confirme;
 
               $portfolioId $userInfo->id_portfolio;

 
               if(isset($userId) && isset($userOK) && isset($portfolioId)) {
 
                   $this->session->set_userdata(array(
 
                       'user_id' => (int)$userId,
 
                       'portfolio_id' => $portfolioId,
 
                       'is_confirmed' => (int)$userOK,
 
                       'logged_in' => (bool)true
                    
));

 
                   $this->load->template('Home_view');
 
               }
 
           } else {
 
               $data['error'] = "Mot de passe incorrect ou utilisateur inexistant.";
 
               $this->load->template('Login_view'$data);
 
           }
 
       }
 
   



Model: Login_model
PHP Code:
class Login_model extends CI_Model {

 
   public function check_user_credentials($mail) {
 
       return $this->db->query("CALL sp_checkUserCredentials(?)"$mail)->result()['0'];
 
   }

 
   public function get_user_info($mail) {
 
       $this->db->select(array('utilisateur.id_utilisateur''confirme''utilisateur.id_portfolio'));
 
       $this->db->from('utilisateur');
 
       $this->db->join('portfolio''utilisateur.id_utilisateur = portfolio.id_utilisateur''inner');

 
       return $this->db->get()->result();
 
       //return $this->db->query("CALL sp_getUserInfo(?)", $mail)->result()['0'];
 
   }


So here's the problem:

From the controller, when I try to fetch the results using the function get_user_info(), an error is triggered, saying that I'm trying to call the function result() from a non-object. So I'm assuming that nothing returns from the query, or that it is not even triggered.

The query is fully fonctional in MySQL, I get all the fields I want.

The first function check_user_credentials() is working, but when it comes to the second one, get_user_info(), that is where the issue happens.

After a while debugging this, I find out that when commenting the "$storedPassword = $this->login->check_user_credentials($mail);" line, the results from the get_user_info() function are shown.

So have you ever seen something like that, do I miss something?

Thank you.

JohnSmoh.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB