我的项目有 3 个应用程序共享一个 codeigniter 安装。它工作得很好,直到我更改了 mysql 表的名称,并更改了查询以反射(reflect)数据库的新更改。现在看起来我的插入查询已被缓存,并尝试将值插入旧表(不再存在)。这是我到目前为止所尝试过的:
CI:
$this->db->cache_delete_all()
mysql:
RESET QUERY CACHE;
在config/database.php中:
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
当 db_debug 配置设置为 TRUE 时,它会给出 500 错误,当设置为 FALSE 时,我能够捕获错误,结果发现它正在尝试插入到不再存在的旧表中。我不明白这怎么可能,我什至搜索了我的整个项目,但在我的项目中的任何地方都找不到旧的表名,而且 CI 缓存文件夹是空的。任何帮助将不胜感激。
编辑:我的插入代码:
if($this->db->insert('booking_calendar', $data))
{
$booking_id = $this->db->insert_id();
$this->load->helper('string');
$order_id = strtoupper(random_string('alnum', 6)) . $booking_id;
$data = array(
'id' => $order_id,
'booking_calendar_id' => $booking_id,
'status' => 'PAYMENT_PENDING'
);
if($this->db->insert('bookings', $data))
{
$this->notifications->add($MYSELF['id'], 'Court successfully booked.');
return $order_id;
}
$this->notifications->add($MYSELF['id'], 'Court booking failed.', 'warning');
return false;
}
else
{
log_message('ERROR', 'Insert booking_calendar failed. ' . print_r($this->db->_error_message(), true));
}
这是我日志中的输出:
ERROR - 2013-09-23 20:05:13 --> Insert booking_calendar failed. Table 'tennis.courts_calendar' doesn't exist
通知是自定义类,仅在“通知”表中插入一行。
最佳答案
我找到了问题的答案,我的表上有 ON BEFORE INSERT/UPDATE 触发器,当我更改它的名称时,结果发现使用新名称在同一个表上插入仍然会触发旧表名而不是新表名。所以我刚刚更新了触发器,现在它可以工作了。希望这能为其他人节省时间,因为即使从现在的角度来看这看起来微不足道,我也花了一段时间。
关于php - Codeigniter 事件记录查询已缓存 - 查找旧表名而不是新表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18948248/