Welcome Guest, Not a member yet? Register   Sign In
Begin Transaction Not Work
#1
Bug 

Sorry everyone i need help about using trans_begin() to handle mutiple insert with multi table, im try  to insert data "Tagihan" after insert data 'Santri' but ihave a problem. in query insert data "Santri" is success but not in "Tagihan" because in "Tagihan" field "biaya_id" is unknown..

i mean with trans_begin the Data will be rollback or not insert when getting error in query...
PHP Code:
$this->db->trans_begin();

 
       $this->db->set($data)->insert('santri');

 
       $santri_id $this->db->insert_id();
 
       $kelas_id  $data['kelas_id'];

 
       $this->db->select('biaya_id, nominal');
 
       $this->db->from('biaya_per_kelas');
 
       $this->db->where('kelas_id'$kelas_id);

 
       $query  $this->db->get();

 
       if ($query->num_rows() > 0){
 
           foreach ($query->result_array() as $biaya) {
 
               $this->db->set('santri_id'$santri_id);
 
               $this->db->set('biaya_id'$biaya['biaya_id']);
 
               $this->db->set('nominal'$biaya['nominal']);
 
               $this->db->insert('tagihan');
 
           }
 
       }

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

 
           return true;
 
       } else {
 
           $this->db->trans_commit();

 
           return false;
 
       
Reply
#2

Does this query in your script return expected values?
PHP Code:
$this->db->select('biaya_id, nominal');
$this->db->from('biaya_per_kelas');
$this->db->where('kelas_id'$kelas_id);
$query  $this->db->get();
print_r($query->result()); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB