如果在我要回滚已提交查询的任何表中出现任何错误时,我都需要插入2个表中。
我在控制器内部编写了查询,例如:
$this->db->trans_start();
$this->db->insert_batch('market_users_mapping', $marketData);
$this->db->insert_batch('maincategory_users_mapping', $maincategoryData);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
throw error
}
Run Code Online (Sandbox Code Playgroud)
这很完美。但是我认为在控制器内部编写查询不是一个好习惯。因此,我做到了这一点,称为模型函数,并在相应的模型函数中编写了这些insert_batch查询。
$this->db->trans_start();
$this->maincategory_model->function_name()
$this->market_model->function_name();
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
throw error
`enter code here`
}
Run Code Online (Sandbox Code Playgroud)
但这没有按预期工作