title: codeigniter batch_update-insert confirmation
body: <p>I have this function that does following</p>
  
  <pre><code>function save($owner,$data){
  ///$owner='00002';$data=[['type1','value1'],['type','value2']];
  ///check if this $data is already in database, if +ve and != then update else insert
          $sel='';$rs=[];$ins=FALSE;$up=FALSE;$end=[];
  
          $this-&gt;db-&gt;select('id,type,value')-&gt;where('owner',$owner)
  
          //building WHERE statment
          foreach(array_keys($data)as $k)
              $sel.="type='$k' OR ";
  
          $this-&gt;db-&gt;where("(".trim($sel,' OR ').")");
  
          $r=$this-&gt;db-&gt;get('settings');
  
          if($r-&gt;num_rows() &gt; 0)//building reference array
              foreach($r-&gt;result() as $r)$rs[$r-&gt;type]=$r;
  
          foreach($data as $t=&gt;$v)
          {
              if(isset($rs[$t])){//case input already in db--&gt;update
                  if(!$v || $v!=$rs[$t]-&gt;value)$up[]=['id'=&gt;$rs[$t]-&gt;id,'value'=&gt;$v,'archived'=&gt;0];
              }else{//case not--&gt;insert
                  if($v)$ins[]=['type'=&gt;$t,'value'=&gt;$v,'owner'=&gt;$owner];
              }   
          }
  
          $this-&gt;db-&gt;insert_batch('settings',$ins);
          $this-&gt;db-&gt;update_batch('settings',$up,'id');
      }
  </code></pre>
  
  <p>Now how can i confirm that insert_batch and update_patch both worked and how return how many fields where updated ..
  i tried using db->affected_rows() but since im using 2 statements its return is not accurate. </p>
  
  <p>any ideas?</p>