Codeigniter - transactions stored procedure

0

Is it possible ?, they work as they should? do transactions by invoking store procedure from query builder ?, that is, the changes are reversed with rollback in case of error ?, thanks.

    $this->db->trans_start();
$this->db->query('call sp_uno()');
$this->db->query('call sp_dos()');
$this->db->query('call sp_tres()');
$this->db->trans_complete(); 

if ($this->db->trans_status() === FALSE)
{
        $this->db->trans_rollback();
}
else
{
        $this->db->trans_commit();
}
    
asked by Incubux Succubux 13.05.2018 в 07:44
source

1 answer

1

You can do it in the following way:

$this->db->trans_begin();

$this->db->query('SQL QUERY...');
$this->db->query('OTRA QUERY...');
$this->db->query('OTRA QUERY...');

if ($this->db->trans_status() === FALSE){
        $this->db->trans_rollback();
}else{
        $this->db->trans_commit();
}
  • You use $this->db->trans_begin(); to start the transaction.
  • You conduct the consultations.
  • Verify the status of the transaction using $this->db->trans_status(); .
  • If the Status is TRUE you confirm using $this->db->trans_commit(); .
  • If the Status is FALSE you cancel using $this->db->trans_rollback(); .
  •   

    Basically this is a manual transaction, but Traditionally, the   transactions have required a good amount of work for their   implementation, since they require you to keep track of your   consultations and determine whether to commit or retract according to   of the success or failure of your consultations. This is particularly   uncomfortable in the case of nested queries. On the contrary, it   I implement an intelligent transaction system that does all this   by you automatically (you can also manage your transactions   manually if you wish, but in reality there is no   benefit).

    Reference: Codeigniter Transaction

        
    answered by 15.05.2018 / 01:57
    source