0
$this->db->trans_start();
        $obj = array(
                'id_supplier'=>$idsupplier,
                'nama_cp'=>$namacp,
                'email'=>$email,
                'note'=>$note
        );
        $this->supplier_model->updateSupplier($obj);

        $this->supplier_bahan_baku_model->deleteSupplierBahanBakuByIdSupplier($idsupplier);
        for($i = 0; $i < count($bb); $i++) 
        {
            $obj2 = array(
                'id_supplier'=>$idsupplier,
                'id_bb'=>$bb[$i]
            );
            //print_r($obj2);
            $this->supplier_bahan_baku_model->insertSupplierBahanBaku($obj2);
        }

        $this->db->trans_complete();    
        if($this->db->trans_status() === TRUE)
        {
            if($this->db->affected_rows() > 0)
            {
                echo 1;
            }
            else
            {
                echo 0;
            }
        }

I need to know the affected rows for some reason.. And I need to use db transaction because there are many query.. Please help me.. Thank You ^^

TA Fighting
  • 23
  • 1
  • 4
  • What error are you getting or does your transaction status always return false? – Nikhil G Aug 18 '17 at 13:43
  • Possible duplicate of [Check if db->update successful with Codeigniter when potentially no rows are updated](https://stackoverflow.com/questions/20030642/check-if-db-update-successful-with-codeigniter-when-potentially-no-rows-are-upd) – Mayank Vadiya Aug 18 '17 at 13:49
  • First check yourself and then ask here. – Mayank Vadiya Aug 18 '17 at 13:49
  • @MayankVadiya not exactly a duplicate, but the 2nd and 5th answers do explain how to use affected_rows. – Goose Aug 18 '17 at 14:26
  • @nikhil_gandhi The transaction status works. But the affected rows always return false, but when i see it in my sql database it works fine – TA Fighting Aug 18 '17 at 15:14
  • Ok. In the else part try to log the error and than revert me what you are getting. – Nikhil G Aug 18 '17 at 15:17
  • @nikhil_gandhi try this: error_reporting(E_ALL); ini_set('error_reporting', E_ALL); But I cant see any error – TA Fighting Aug 18 '17 at 15:25

1 Answers1

0

I think what you want is this.

$this->db->affected_rows();

It will return the affected rows, or will return 0 if no rows were effected.

Goose
  • 4,764
  • 5
  • 45
  • 84