CodeIgniter 3中的事务功能如何与查询一起使用



所以我在模型中有此查询。

$this->db->trans_begin();
$this->db->insert($somequeryhere);
$this->db->insert($somequeryhere2);
$this->db->insert($somequeryhere3);
$this->db->insert($somequeryhere4);
$this->db->update($somequeryhere7);
$this->db->update($somequeryhere21);
$this->db->delete($somequeryhere10);
if($this->db->trans_status() === FALSE){
   $this->db->trans_rollback(); return false;
}else{
   $this->db->trans_commit(); return true;
} 

交易肯定效果很好。但是,当我尝试在查询中间像查询一样死亡PHP过程时,这会令人困惑。

$this->db->trans_begin();
$this->db->insert($somequeryhere);
$this->db->insert($somequeryhere2);
$this->db->insert($somequeryhere3);
$this->db->insert($somequeryhere4);
die;
$this->db->update($somequeryhere7);
$this->db->update($somequeryhere21);
$this->db->delete($somequeryhere10);
if($this->db->trans_status() === FALSE){
   $this->db->trans_rollback(); return false;
}else{
   $this->db->trans_commit(); return true;
} 

交易仍然有效。我认为PHP没有达到$this->db->trans_status(),因此交易将无法正常工作,但这也工作于使用或不使用$this->db->trans_status()。有人可以解释一下吗?

我尝试使用$this->db->trans_start();$this->db->trans_complete();,但仍执行事务回滚。

如果在trans_begin((之后将模具放在代码的中间。它不会提交,如果要检查插入更新数据的状态,则不得对此方法使用trans方法。

因为对于trans方法 - 提交或回滚需要执行查询

//$this->db->trans_begin();
$this->db->insert($somequeryhere);
$this->db->insert($somequeryhere2);
$this->db->insert($somequeryhere3);
$this->db->insert($somequeryhere4);
die;
$this->db->update($somequeryhere7);
$this->db->update($somequeryhere21);
$this->db->delete($somequeryhere10);

最新更新