开发者

CodeIgniter : Transaction ERROR vs MySQL ERROR

开发者 https://www.devze.com 2023-03-10 01:21 出处:网络
How can I tell if the transaction was FALSE or if something else happened(locked table)? $this->db->trans_start();

How can I tell if the transaction was FALSE or if something else happened(locked table)?

    $this->db->trans_start();

    $this->db->where('id', $id)
             ->limit(1);

    $q = $this->db->delete('table');

    $this->db->trans_complete();

    return $this->db->trans_status() ? TRUE : FALSE;

For example, the transaction might fail because of a foreign开发者_开发问答 key constraint. If that is the case I would run another query. In any other case I want to retry the original query.


Check if the query was succesfull

if($q)
 echo ok 
else
 echo ko
0

精彩评论

暂无评论...
验证码 换一张
取 消