【问题标题】:Converting SQL query to Codeigniter Active Record将 SQL 查询转换为 Codeigniter 活动记录
【发布时间】:2014-03-21 20:36:43
【问题描述】:

我有这个 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%'

如何将其转换为 Codeigniter Active Record?

提前致谢!

【问题讨论】:

    标签: mysql sql codeigniter activerecord


    【解决方案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();
    

    Active Record Class

    【讨论】:

    • 完美运行;非常感谢您的快速回复。
    猜你喜欢
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    相关资源
    最近更新 更多