Codeigniter トランザクションを使用しています
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->trans_complete();
これは正常に動作します。私が抱えている問題は、内部でtrans_start
他trans_complete
の関数を呼び出しており、それらの関数がデータベースを処理しているため、挿入と更新といくつかの削除が含まれていることです...例:
$this->db->trans_start();
$this->utils->insert_function($data);
$this->utils->update_function2($test);
$this->db->trans_complete();
これらの関数が実行され、何らかのエラーが発生した場合、CodeIgniter はロールバックを行いません。
そのような問題に対処する最善の方法は何ですか?
私が念頭に置いている唯一の解決策は、これらの関数からエラーを返し、それらの関数内に ( trans_stat
and trans_complete
) を追加することです。$this->db->trans_rollback
元:
$this->db->trans_start();
$result = $this->utils->insert_function($data);
if($result === false){
$this->db->trans_rollback();
}
$this->db->trans_complete();
これを行うより良い方法はありますか?
更新 1:
要求されたように、私が呼び出している外部関数のサンプル:
// insert_function contains
$rec = array(
'numero' => $numero,
'transaction_id' => $id,
'debit' => $product_taxes['amount_without_taxes'],
'date' => $data['date_transaction'],
);
$this->addExerciceAccountingRecords($rec);
and addExerciceAccountingRecords contains
function addExerciceAccountingRecords($records) {
$this->db->insert('transactions_exercices', $records);
}