아래 코드가 있습니다. 트랜잭션이 실패하면 롤백되지 않습니다. 잠금 테이블 문을 제거하면 롤백됩니다. 자물쇠 및 거래를 사용하기 위해해야 할 특별한 것이 있습니까?php/mysql 트랜잭션이 실패시 롤백되지 않습니다 (Codeigniter 프레임 워크)
function save ($items,$customer_id,$employee_id,$comment,$show_comment_on_receipt,$payments,$sale_id=false, $suspended = 0, $cc_ref_no = '', $auth_code = '', $change_sale_date=false,$balance=0, $store_account_payment = 0)
{
if(count($items)==0)
return -1;
$sales_data = array(
'customer_id'=> $this->Customer->exists($customer_id) ? $customer_id : null,
'employee_id'=>$employee_id,
'payment_type'=>$payment_types,
'comment'=>$comment,
'show_comment_on_receipt'=> $show_comment_on_receipt ? $show_comment_on_receipt : 0,
'suspended'=>$suspended,
'deleted' => 0,
'deleted_by' => NULL,
'cc_ref_no' => $cc_ref_no,
'auth_code' => $auth_code,
'location_id' => $this->Employee->get_logged_in_employee_current_location_id(),
'store_account_payment' => $store_account_payment,
);
$this->db->trans_start();
//Lock tables invovled in sale transaction so we don't have deadlock
$this->db->query('LOCK TABLES '.$this->db->dbprefix('customers').' WRITE, '.$this->db->dbprefix('sales').' WRITE,
'.$this->db->dbprefix('store_accounts').' WRITE, '.$this->db->dbprefix('sales_payments').' WRITE, '.$this->db->dbprefix('sales_items').' WRITE,
'.$this->db->dbprefix('giftcards').' WRITE, '.$this->db->dbprefix('location_items').' WRITE,
'.$this->db->dbprefix('inventory').' WRITE, '.$this->db->dbprefix('sales_items_taxes').' WRITE,
'.$this->db->dbprefix('sales_item_kits').' WRITE, '.$this->db->dbprefix('sales_item_kits_taxes').' WRITE,'.$this->db->dbprefix('people').' READ,'.$this->db->dbprefix('items').' READ
,'.$this->db->dbprefix('employees_locations').' READ,'.$this->db->dbprefix('locations').' READ, '.$this->db->dbprefix('items_tier_prices').' READ
, '.$this->db->dbprefix('location_items_tier_prices').' READ, '.$this->db->dbprefix('items_taxes').' READ, '.$this->db->dbprefix('item_kits').' READ
, '.$this->db->dbprefix('location_item_kits').' READ, '.$this->db->dbprefix('item_kit_items').' READ, '.$this->db->dbprefix('employees').' READ , '.$this->db->dbprefix('item_kits_tier_prices').' READ
, '.$this->db->dbprefix('location_item_kits_tier_prices').' READ, '.$this->db->dbprefix('location_items_taxes').' READ
, '.$this->db->dbprefix('location_item_kits_taxes'). ' READ, '.$this->db->dbprefix('item_kits_taxes'). ' READ');
$this->db->insert('sales',$sales_data);
$sale_id = $this->db->insert_id();
//A bunch of mysql other queries to save a sale
$this->db->query('UNLOCK TABLES');
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
return -1;
}
return $sale_id;
}
그냥 후속 질문을. 이 작업을 수행하고 오류가 있어도 트랜잭션이 부분적으로 커밋 된 것 같습니다. 오류가있는 경우 트랜잭션이 커밋되지 않은 위치에서이 작업을 수행 할 수 있습니까? –