簡體   English   中英

codeigniter多個OR查詢

[英]codeigniter multiple OR query

我想在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正確的語法是什么?

可能是您的查詢在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')'");

您應該使用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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM