繁体   English   中英

如何以正确的“ Codeigniter方式”编写此SQL查询?

[英]How can I write this SQL query in the correct 'Codeigniter way'?

我目前正在使用Codeigniter到期,并且在模型中有如下查询:

function retrieve_user($user_id)
    {
        // TODO: Update this query to correct CI syntax
        $query = "SELECT user_id, username, email, banned, created, avatar, country, gender, user_level FROM users, user_profiles WHERE users.id = user_profiles.id AND users.id = ?";
        $values = array($user_id);
        return $this->db->query($query, $values)->row_array();
    }

这行得通,我对结果感到满意,但是出于良好的编码习惯,我希望使用记录的CI格式编写此文件。

谁能帮我这个忙吗? 我已经阅读了文档,但是发现自己对将其付诸实践有些困惑。

尝试这样:

 $this->db->select('user_id, username, email, banned, created, avatar, country, gender, user_level');
$this->db->from('users');
   $this->db->join('user_profiles', 'user_profiles.id = users.id');
    $this->db->where('users.id =', 'user_profiles.id');
$this->db->where('users.id =', '?');

请尝试遵循以下详细信息: http : //www.codeigniter.com/user_guide/database/active_record.html

$this->db->select('user_id, username, email, banned, created, avatar, country, gender, user_level FROM users, user_profiles')->join('user_profiles','user_profiles.id = users.id')->get_where('users',array(users.id=>$user_id))->result();

这是参考网址: https : //ellislab.com/codeigniter/user-guide/database/active_record.html#select

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM