I had problem running a query and counting the results with this code:
$this->db->get_where('user_tb', array('username' => $username, 'password' => $password) );
$count = $this->db->count_all_results();
And it always return 1
even if the username and password are wrong.
Then I changed my code to:
$sql = "SELECT * FROM user_tb WHERE username = ? AND password = ?";
$this->db->query($sql, array($username, $password));
$count = $this->db->count_all_results();
But the result is still the same.
Then my third and last try, I changed the code to:
$this->db->where('username', $username);
$this->db->where('password', $password);
$this->db->from('user_tb');
$count = $this->db->count_all_results();
Then it works. What are the differences between this three? Why is the last set of code works and the other two did not?