转换SQL查询来笨的Active Record(Converting SQL query to Co

2019-10-19 15:56发布

我有这样的SQL查询

SELECT *
FROM adm_species t
JOIN adm_breeds e ON e.species_id = t.id
JOIN fd_registrations s ON s.breeds_id = e.id
WHERE t.code = 'cat'
AND s.sex_id = '2'
AND s.ownername LIKE '%sha%'

如何转换这笨活动记录?

提前致谢!

Answer 1:

尝试这个

$this->db->select('*');
$this->db->from('adm_species t');
$this->db->join('adm_breeds e', 'e.species_id = t.id');
$this->db->join('fd_registrations s', 's.breeds_id = e.id');
$this->db->where('t.code', 'cat');
$this->db->where('s.sex_id', 2);
$this->db->like('s.ownername', 'sha', 'both'); 
$query = $this->db->get();

活动记录类



文章来源: Converting SQL query to Codeigniter Active Record