2

我想在 Codeigniter 中使用以下查询:

SELECT `users` . * , `users_profile` . * FROM (`users`) LEFT JOIN `users_profile`
ON `users`.`id` = `users_profile`.`users_id`
WHERE (`loginid` = '$username' OR `email` = '$username' )
AND `password` = '$password' AND `users`.`status` = 'A' LIMIT 1 

它工作正常,但是当我以 Codeigniter 格式编写此查询时:

$this->db->where('loginid',"$username");
$this->db->or_where('email', "$username");    
$this->db->where('password',MD5($password));
$this->db->where('users.status','A');
$this->db->limit(1);

它将始终返回 true 什么是正确的语法?

4

2 回答 2

3

可能您的查询在codeIgniter中应该是这样的......作为参考,您可以看到这个链接 参考

$this->db->select('*');
$this->db->from('users');
$this->db->join('users_profile', 'users_profile.id = users.id', 'left');
$this->db->where("(loginid = '$username' OR email = '$username') AND password = 'MD5($password) AND status = 'A')'");
于 2012-11-26T09:05:45.577 回答
1

您应该使用 where() 的自定义字符串方法,因为仅使用 ActiveRecord 是无法直接实现的。请参阅文档中的此链接并滚动到 where() 函数下的第 4 个选项。

例子:

    Custom string:

    You can write your own clauses manually:
    $where = "name='Joe' AND status='boss' OR status='active'";

    $this->db->where($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);
于 2012-11-26T08:53:11.647 回答