CodeIgniter Forums
CI's mysql transction question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: CI's mysql transction question (/thread-9109.html)



CI's mysql transction question - El Forum - 06-12-2008

[eluser]chmod[/eluser]
<?
...

$this->db->trans_start();
//扣除游票
$result_sub_payment = $this->payforgame_model->sub_payment($username,$payment);
//写消息到临时表中:payforgame_tmp
$privatekey = '[email protected]';
$base64_username = base64_encode($username);
//md5加密串, accName(base64编码后)+creditNum+orderId+约定码
$digit = md5($base64_username.$point.$orderId.$privatekey);
$result_payforgame_tmp = $this->payforgame_model->payforgame_tmp($username,$gameid,$areaid,$payment,$orderId,$digit);
//事务处理结束
$this->db->trans_complete();

...
?>


I use CI's transaction as above.

because the SQL query in my model,so I am not sure the transction will be run?


CI's mysql transction question - El Forum - 06-12-2008

[eluser]gtech[/eluser]
you can start and stop your transaction as you describe no problems (make sure you turn db_debug to FALSE or transactions do not work). The only problem you will find is when you call a transaction within a transaction, e.g. if payforgame_tmp had a trans_start and trans_complete the transaction would not work.


Even though the transaction will work in the above code, I personally think it makes more sense to engineer your code so that the transactions are left in the model (you can call functions that are in the same model).


CI's mysql transction question - El Forum - 06-13-2008

[eluser]chmod[/eluser]
good,thanks.