CI framework $this->db->where not get results

Source: Internet
Author: User
Keywords Php mysql
Use CI to write the login code, with $this->db->where query the database to verify the account password is always empty return value
The following are the function codes that are validated in the controller:

public function validate_credentials(){        $this->load->model('Bookmark_models');        $query = $this->Bookmark_models->where();                if ($query){            $data = array('username' => $this->input->post('username'),                          'is_loggrd_in' => true);            $this->session->set_userdata($data);            $this->load->view('logged_in_area');        }else {            $this->login();        }

The following is the code in the model:

public function where(){        $this->db->where('username',$this->input->post('username'));        $this->db->where('passwd',sha1($this->input->post('password')));        $query = $this->db->get('user');                if ($query->num_rows == 1){            return true;        }

Reply content:

Use CI to write the login code, with $this->db->where query the database to verify the account password is always empty return value
The following are the function codes that are validated in the controller:

public function validate_credentials(){        $this->load->model('Bookmark_models');        $query = $this->Bookmark_models->where();                if ($query){            $data = array('username' => $this->input->post('username'),                          'is_loggrd_in' => true);            $this->session->set_userdata($data);            $this->load->view('logged_in_area');        }else {            $this->login();        }

The following is the code in the model:

public function where(){        $this->db->where('username',$this->input->post('username'));        $this->db->where('passwd',sha1($this->input->post('password')));        $query = $this->db->get('user');                if ($query->num_rows == 1){            return true;        }

Use echo $this->db->last_query(); the output native SQL statement to execute in the database to see if there is any result.
num_rows()is a method rather than a property
In addition, it is not recommended that you write this, the model is not recommended to do the controller.

public function login($user, $password)    {        return $this->db->where('username', $user)            ->where('password', sha1($password))            ->get('user')            ->row();    }
public function where(){        $this->db->where('username',$this->input->post('username'));        $this->db->where('passwd',sha1($this->input->post('password')));        $query = $this->db->get('user');        echo $this->db->last_query();exit();        if ($query->num_rows() ){            return true;        }        return false;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.