【发布时间】:2014-02-02 15:48:04
【问题描述】:
codeigniter 代码序列的行为相当奇怪。 在模型中,下面的代码不起作用,并且不会更新数据库:
$this->db->set($data);
$this->db->where($this->_primaryKey, $id);
$this->db->update($this->_tableName);
如果我在它们之前添加一个虚拟指令并使序列如下所示
$this->db->update('pages', array('body'=>'hhfhj@gmail.com'), "id = 7");
//The above statement need not to have any connection with the table I am updating.
// But unless I add the above statement, the statement below are not able to update the database.
$this->db->set($data);
$this->db->where($this->_primaryKey, $id);
$this->db->update($this->_tableName);
我不明白,那个额外的语句做了什么,codeigniter 活动记录功能开始工作而不是其他情况。
第一种情况生成的查询是:
"UPDATE `users` SET `name` = 'Shashank Jagetiya', `email` = 'other@gmail.com', `password` = 'a' WHERE `id` != '2' AND `id` = 2"
第二种情况生成的查询是:
"UPDATE `users` SET `name` = 'Shashank Jagetiya', `email` = 'adfddfaf@gmail.com', `password` = 'a' WHERE `id` = 2"
好的,我知道之前的某些情况仍然存在或其他情况......我不知道这是从哪里来的,也不知道如何删除它
【问题讨论】:
-
你打印了最后一个查询吗?
-
请贴出您的完整代码,即$data的内容。
-
如果之前的情况仍然存在,您可以在更新部分开始之前使用
$this->db->reset();。 -
我已经发布了这两种情况下的查询。所以 $data 也很清楚。在第一种情况下
id!= '2' 之后的额外部分,我不明白它来自哪里 -
能否请您发布上次查询的回显结果?
标签: database codeigniter activerecord