问题
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