Using separate model methods to manage transactions
Posted
by DCrystal
on Stack Overflow
See other posts from Stack Overflow
or by DCrystal
Published on 2010-03-19T00:07:57Z
Indexed on
2010/03/19
0:11 UTC
Read the original article
Hit count: 653
If i’ve got 2(or more) model methods which do (for example, in billing system) enrolling/withdrawing, and one controller’s method that calls 2(or more) of these model methods.
Is it a good way(maybe, any suggestions how to do it better) to write/use 2model methods like these:
public function start_transaction(){
$this->db->trans_start();
}
public function end_transaction(){
$this->db->trans_complete();
}
And call in controller’s method:
public function smth(){
//something
$this->model->start_transaction();
$this->model->enroll();
//something else
$this->model->withdraw();
$this->model->end_transaction();
}
Will transaction be reversed, if model's withdraw() method fails?
Thanks.
© Stack Overflow or respective owner