Welcome Guest, Not a member yet? Register   Sign In
Session message disappears if db transaction is enabled - bug?
#8

Thanks to Narf for the info on sessions and rollback!

It makes sense that all database changes, which has to include setting session data, will be rolled back the moment you leave the calling controller.

What I have done, instead, is use manual transactions. This allows me to rollback explicitly during error conditions, prior to setting a flash message.

Code:
        // Use manual transactions so that you can explicitly rollback prior to setting
        // a flash message in the session
        //$this->db->trans_start();
        $this->db->trans_begin();
        $this->db->where('transaction_id', $transaction_id);
        $data = array(
                'friend_id'        => 'Hey man!', //$friend_id,
                'gross'            => $gross,
                'fee'            => $fee,
                'net'            => $net,
                'agency_transaction' => $agency_transaction,
                'receipt_number'    => $receipt_number
        );
        if (!$this->db->update('donations', $data)) {
            $error = $this->db->error();
            $this->db->trans_rollback();
            throw new Exception('Donations_model->update: ' . $error['code'] . ' ' . $error['message']);
        }
        $this->db->trans_commit();
        //$this->db->trans_complete();
        return TRUE;
Reply


Messages In This Thread
RE: Session message disappears if db transaction is enabled - bug? - by Shawn - 01-03-2016, 03:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB