CodeIgniter Forums
Transactions do not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Transactions do not work (/thread-71111.html)



Transactions do not work - girub - 07-07-2018

hello everyone, someone will know me to say what am I wrong ...? transactions do not work or maybe something else ...
I expect that if there is an error in the insert the transaction does not even update ... instead update is always performed ...
what do you recommend?
I did a lot of tests trying also with manual transaction .. but nothing
thank you so much
Giuseppe
and sorry for my english !!

I attach the relevant code



PHP Code:
 $this->db->trans_start();

 
           foreach ($libriInVisione as $value) {

 
               $value explode("|"$value);
 
               $idMagazzino $value[0];
 
               $quantita $value[1];

 
               $this->db->set('quantita''quantita - ' $quantitafalse);
 
               $this->db->set('data_modifica_riga''NOW()'FALSE);
 
               $this->db->where('id'$idMagazzino);
 
               $this->db->update('magazzino');


 
               $this->db->set('id_cliente'$idCliente);
 
               $this->db->set('id_rappresentante'$idRappresentante);
 
               $this->db->set('id_magazzino'$idMagazzino);
 
               $this->db->set('bolla_visione'$bollaVisione);
 
               $this->db->set('quantita'$quantita);
 
               $this->db->set('quantita_visione'$quantita);

 
               //$dataVisione = '23-5-2016 23:15:23';
 
               $dataVisione_formattata date("Y-m-d"strtotime($dataVisione));

 
               $this->db->set('data_visione'$dataVisione_formattata);
 
               $this->db->set('data_inserimento_riga''NOW()'FALSE);
 
               $this->db->set('data_modifica_riga''NOW()'FALSE);
 
               $this->db->set('is_active'1);
 
               $this->db->set('operatore'$this->session->userdata['name']);

 
               $this->db->insert('in_visione');
 
           }

 
       $this->db->trans_complete();

 
       if ($this->db->trans_status() === FALSE) {
 
           $this->db->trans_rollback();
 
       } else {
 
           $this->db->trans_commit();