공부
PHP Transactions
보라색코르테즈
2014. 1. 13. 14:21
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
// generate an error... or use the log_message() function to log your error
}
$this->db->trans_start()함수를 호출하면 트랜잭션은 자동으로 활성화 됩니다. 트랜잭션을 비활성화 시키고 싶다면 ,$this->db->trans_off() 함수를 호출하시면됩니다.
수동처리
$this->db->trans_begin();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
출처 : http://codeigniter-kr.org/user_guide_2.1.0/database/transactions.html
728x90