mysql - CodeIgniter - SQL Query AND clause with table columns -
i'm new codeigniter , i'm struggling active record class , apostrophes adds query:
this query codeigniter outputs (via enable_profiler):
select `login`.`idlogin`, `login`.`username`, `login`.`password` (`login`, `pessoa`) `login`.`username` = 'user1' , `login`.`password` = 'pass1' , `pessoa`.`nbi` = 'login.pessoa_nbi' limit 1
user1 , pass1 strings login form (ignore password in plain cleartext). produces 0 results.
however correct query, i.e., result want is:
select `login`.`idlogin` , `login`.`username` , `login`.`password` (`login` , `pessoa`) `login`.`username` = 'user1' , `login`.`password` = 'pass1' , `pessoa`.`nbi` = login.pessoa_nbi limit 1
only difference penultimate line, login.pessoa_nbi isn't surrounded apostrophe.
which produces out 1 result, should. database mysql.
edit: here active record code:
$this -> db -> select('login.idlogin, login.username, login.password'); $this -> db -> from('login,pessoa); $this -> db -> where('login.username', $username); $this -> db -> where('login.password', $password); $this -> db -> where('pessoa.nbi', login.pessoa_nbi'); $this -> db -> limit(1);
what doing wrong?
thanks
activerecord where
provides parameter codigniter not escape data
$this->db->where() accepts optional third parameter. // if set false, codeigniter not try protect field or // table names backticks. $this->db->where('match (field) against ("value")', null, false);
you can use join though query
$this->db->select('l.idlogin, l.username, l.password'); $this->db->from('login l'); $this->db->join('pessoa', 'pessoa.nbi = l.pessoa_nbi'); $this->db->where('l.username', 'usernam'); etc..
Comments
Post a Comment