【问题标题】:CodeIngiter "WHERE AND OR" to Active RecordCodeIgniter "WHERE AND OR" 到 Activerecord
【发布时间】:2015-03-08 09:32:05
【问题描述】:
我想像这样进行 CodeIgniter Active Records 查询。
SELECT * FROM user WHERE user_name = 'email'
AND (user_password='123' OR second_password = '456')
我已经尝试了一些代码,但无法正常工作。我正在使用 CI 2.2.0
【问题讨论】:
标签:
php
mysql
codeigniter
activerecord
【解决方案2】:
简写版:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where('username', $name)->where($where)->get('myTableName');
$this->db->where() 已经充当SELECT FROM * 除非您只想选择某些列。
$this->db->select(); 注意:如果从表中选择所有 (*)
你不需要使用这个功能
【解决方案3】:
我有一个简单的解决方案,谢谢大家。
$this->db->select('*');
$this->db->from('user');
$this->db->where('user_name', 'email');
$this->db->where('user_password', '123');
$this->db->or_where('user_name', 'email');
$this->db->where('second_password', '456');
$query = $this->db->get();