[英]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.