• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Force database transaction to rollback.

#1
[eluser]Fábio[/eluser]
Hi,

How do I force a transaction to rollback, using the automatic method.
( The manual method supports nested transactions in MySQL? As far as I know it does not support. )

Code:
try
{
    // Begin first transaction
    $this->db->trans_start();
    $this->db->query('<anything>');

        // Begin nested transaction
        $this->db->trans_start();
        $this->db->query('<anything>');

        // Some 'assertion' code
        if( true )
            throw new Exception('Force everything to rollback');

        $this->db->trans_complete();

    // Finishing outermost trans
    $this->db->trans_complete();
}
catch(Exception $ex)
{
    // How do I rollback both transactions?
    // $this->db->rollback(); ??
}

Thanks for your attention.

#2
[eluser]CroNiX[/eluser]
Haven't tried it, but I believe you would just have one trans_start. Any queries run after that would be part of the same transaction, wouldn't they? And then one trans_complete() after both queries. Then if you rollback it should roll both queries?

From the transactions userguide:
Code:
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('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
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.