Grouping WHERE clauses in Codeigniter

后端 未结 6 997
陌清茗
陌清茗 2020-11-27 21:02

I want to produce the following SQL code using Active Records in Codeigniter:

WHERE name != \'Joe\' AND (age < 69 OR id > 50)

Doing t

6条回答
  •  半阙折子戏
    2020-11-27 21:44

    What I've done is duplicate the and clause after the where, which is effectively the same as the long string selection.

    $this->db->select()
      ->from('users')
      ->where('name !=', 'Joe')
      ->where('age <', 69)
      ->or_where('id <', $id)
      ->where('name !=', 'Joe');
    

    The one large string way is probably better.

提交回复
热议问题