Ci framework $ this-> db-> where cannot get the result

Source: Internet
Author: User
Use ci to write the logon code. use $ this-& amp; gt; db-& amp; gt; when you query the database to verify the account password, the returned value is always null. The following is the function code verified in the Controller: {code ...} the code in the model is as follows: {code ...} use ci to write the logon code, and use $ this-> db-> where to query the database to verify the account password. The returned value is always null.
The function code verified in the controller is as follows:

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 code in the model is as follows:

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 logon code, and use $ this-> db-> where to query the database to verify the account password. The returned value is always null.
The function code verified in the controller is as follows:

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 code in the model is as follows:

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;        }

Useecho $this->db->last_query();Output native SQL statements to the database for execution to see if there are any results.
num_rows()It is a method rather than a property.
In addition, we do not recommend that you write this statement. We do not recommend that you do controller operations in the model.

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.