Codigniter active record update query taking old where clause

本小妞迷上赌 提交于 2019-12-13 04:05:03

问题


I have a following query

$this->db->set('registerStep', $param)
 ->where('id = ',$user_id)
 ->update($this->table_name);

Above Query is producing below sql code. even though I'm supplying only one where condition.

 UPDATE `users` SET `registerStep` = 2 WHERE `id` = 33 AND `id` = '165'

I think active record is using some cached where condition, is there any way I can free where condition.
I tried using

$this->db->flush_cache();

But it's not helping.


回答1:


http://codeigniter.com/user_guide/database/active_record.html#update

->where('id = ',$user_id)

is incorrect.

->where('id',$user_id)

is correct.




回答2:


Your query is fully correct. But I believe what you used a $this->db->where() before current query. Use the following code and you will see all the previously defined "where" statements:

print_r($this->db->ar_where);
$this->db->set('registerStep', $param)
     ->where('id = ',$user_id)
     ->update($this->table_name);


来源:https://stackoverflow.com/questions/9379644/codigniter-active-record-update-query-taking-old-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!