Welcome Guest, Not a member yet? Register   Sign In
Transaction and error handling
#7

[eluser]InsiteFX[/eluser]
Would be something like this.
Code:
/**
* You can place this in a helper or in your code.
*
* USAGE: $error = $this->show_trans_error('1');
*/
public function show_trans_error($status_code = '')
{
    $trans_errors = array(
        'Transaction Successful!',
        'Error 01: Transaction Insert Failed!',
        'Error 02: Transaction Update Failed!'
    );

    return $trans_errors[(int)$status_code];
}

You could add to the application/config/config.php file a switch for logging etc.
Code:
// this will allow you to either display the error message or log it to the log file.
$config['trans_logging'] = TRUE;

The check:
Code:
$trans_logging = FALSE;    // This is better then using the above $config but your choice!
$error = $this->show_trans_error('0');

if ($this->db->trans_status() === FALSE)
{
    if ($this->trans_logging === FALSE)
    {
        // display however you would like $error.
    }
    else
    {
        // save $error to log file!
        $this->log_message('error', $error);
    }
}

You can do your Rollback and Commit within the above.

InsiteFX


Messages In This Thread
Transaction and error handling - by El Forum - 03-31-2011, 07:04 AM
Transaction and error handling - by El Forum - 03-31-2011, 07:52 AM
Transaction and error handling - by El Forum - 03-31-2011, 07:53 AM
Transaction and error handling - by El Forum - 03-31-2011, 07:56 AM
Transaction and error handling - by El Forum - 03-31-2011, 07:58 AM
Transaction and error handling - by El Forum - 03-31-2011, 08:05 AM
Transaction and error handling - by El Forum - 03-31-2011, 09:00 AM
Transaction and error handling - by El Forum - 03-31-2011, 10:16 AM
Transaction and error handling - by El Forum - 03-31-2011, 10:18 AM
Transaction and error handling - by El Forum - 03-31-2011, 10:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB