我是CodeIgniter的新手,我正在努力处理Active Record类和它添加到我的查询中的撇号:
这是CodeIgniter (通过enable_profiler)输出的查询:
SELECT `login`.`idlogin`, `login`.`username`, `login`.`password`
FROM (`login`, `pessoa`)
WHERE `login`.`username` = 'user1'
AND `login`.`password` = 'pass1'
AND `pessoa`.`nBI` = 'login.pessoa_nBI'
LIMIT 1 user1和pass1是来自登录表单的字符串(忽略明文形式的密码)。这会产生0个结果。
然而,正确的查询,即我想要的结果是:
SELECT `login`.`idlogin` , `login`.`username` , `login`.`password`
FROM (`login` , `pessoa`)
WHERE `login`.`username` = 'user1'
AND `login`.`password` = 'pass1'
AND `pessoa`.`nBI` = login.pessoa_nBI
LIMIT 1 唯一不同的是倒数第二行,login.pessoa_nBI没有用撇号括起来。
这会产生一个结果,这是理所当然的。数据库为MySQL。
编辑:以下是活动记录代码:
$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);我做错了什么?
谢谢
发布于 2013-05-19 06:51:08
Activerecord where提供了一个参数,这样协作者就不会转义您的数据。
$this->db->where() accepts an optional third parameter.
// If you set it to FALSE, CodeIgniter will not try to protect your field or
// table names with backticks.
$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);不过,您可以在查询中使用join
$this->db->select('l.idLogin, l.username, l.password');
$this->db->from('login AS l');
$this->db->join('pessoa', 'pessoa.nBI = l.pessoa_nBI');
$this->db->where('l.username', 'usernam');
etc..https://stackoverflow.com/questions/16629575
复制相似问题