[英]Can not update codeigniter ci_sessions table with custom data
I have added user_id column to ci_sessions table and trying to update it with user id data on login. 我已经在ci_sessions表中添加了user_id列,并尝试在登录时使用用户ID数据对其进行更新。
When I try to update ci_sessions table with using an sql command in model, affected rows returns zero. 当我尝试在模型中使用sql命令更新ci_sessions表时,受影响的行返回零。 Relevant code is this;
相关代码是这个;
public function setUserIdToSession($userId,$sessionId){
$this->db->set('user_id', $userId, FALSE);
$this->db->where('id', $sessionId);
$this->db->update('ci_sessions');
return $this->db->affected_rows();
}
I tried another way to achieve this problem; 我尝试了另一种方法来解决这个问题。
public function setUserIdToSession($userId,$sessionId){
$sql = "UPDATE ci_sessions SET user_id ='$userId' WHERE id='$sessionId'";
$query = $this->db->query($sql);
return $this->db->affected_rows();
}
This function returns zero as well. 此函数也返回零。 What am I doing wrong?
我究竟做错了什么?
try this 尝试这个
$data = array('user_id'=> $userId);
$this->db->where('id', session_id());
$this->db->update('ci_sessions', $data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.