Converting SQL query to Codeigniter Active Record

天涯浪子 提交于 2019-12-11 12:14:52

问题


I have this sql query

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%'

How do I convert this to Codeigniter Active Record?

Thanks in advance!


回答1:


Try this

$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();

Active Record Class



来源:https://stackoverflow.com/questions/22569055/converting-sql-query-to-codeigniter-active-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!