我正在使用CodeIgniter,并且需要使用一个值相继更新两个表(项目和任务)(活动列需要设置为"n").我使用的代码是:
function update($url, $id)
{
$this->db->where('url', $url);
$this->db->update('projects', array('active' => 'n'));
$this->db->where('eventid', $id);
$this->db->update('tasks', array('active' => 'n'));
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,项目表会更新,但任务表不会更新.如果我注释掉,$this->db->update('projects', array('active' => 'n'));那么任务表会更新.
我认为这与缓存有关,但我flush_cache在任务db->update调用之前已经尝试但是没有任何效果.
有人可以解释如何使用CodeIgniter执行连续更新查询吗?
小智 18
使用
$this->db->start_cache();
Run Code Online (Sandbox Code Playgroud)
在开始构建查询之前
$this->db->stop_cache();
Run Code Online (Sandbox Code Playgroud)
结束查询构建后.另外,使用
$this->db->flush_cache();
Run Code Online (Sandbox Code Playgroud)
停止缓存后.
Chr*_*ams 11
这有效:
$this->db->flush_cache();
Run Code Online (Sandbox Code Playgroud)
如果不执行get()或类似CI,则不总是清除缓存.最终代码如下所示:
$this->db->from('table');
$this->db->where('field', $field);
$count = $this->db->count_all_results();
$this->db->flush_cache();
Run Code Online (Sandbox Code Playgroud)
Fem*_*emi 10
第一次通话$this->db->reset();后尝试拨打update电话.
编辑:嗯,尝试$this->db->_reset_write();刷新查询的所有痕迹.
对于Codeigniter的版本3,正确的方法是:
$this->db->reset_query()
如此处所示:http : //www.codeigniter.com/userguide3/database/query_builder.html#resetting-query-builder