事務(wù)操作:
多條sql在一步進(jìn)行的時候避免一條sql出錯 其他sql執(zhí)行 導(dǎo)致數(shù)據(jù)錯亂。這個時候就可以用事務(wù)操作來規(guī)避
開始事務(wù):
$this->trans_start();
提交事務(wù):
$this->trans_comment();
回滾事務(wù):
$this->trans_rollback();
->();
{
=$this->db->()->();->->()->(,)->(, );
->();
}(Exception ) {
->();
[=> , => ];
}
$this->trans_start();
try {
$res=\Phpcmf\Service::M()->db->table('table')->insert($data);
$this->db->table("table")->where('id',$id)->increment('number', 1);
$this->trans_comment();
}catch (\Exception $exception) {
$this->trans_rollback();
return ['code' => 0, 'msg' => '操作異常'];
}
弱弱問一句 ?? trans_comment這個單詞是寫錯了嗎?提交不應(yīng)該是commit嗎
這個是寫錯了?還是有什么歷史原因?