title: Insert Batch php mysql with check duplicate and sum values of field duplicate
body: <p>i have 1 million data using foreach.
  ex table:
  <a href="https://i.stack.imgur.com/q44gI.png" rel="nofollow noreferrer">table</a> </p>
  
  <p>the data
  <a href="https://i.stack.imgur.com/X3fff.png" rel="nofollow noreferrer">data</a>
  i want to inserting that's data using batch/multipleinsert, but i have problem when i got duplicate data. if data duplicate i want the field amount will sum and update amount field with sum amount duplicated data.</p>
  
  <p>this is my code before</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  foreach ($data_transaksi as $key)
        {
            if($key['STATUS_COA'] != $key['CHART_OF_ACCOUNT_STATUS'])
            {
                if($key['ACCOUNT_CATEGORY_CODE'] == '9')
                {
                    $amount = round($key['AMOUNT'],2);
                }
                else
                {
                    $amount = round($key['AMOUNT'],2) *-1;
                }
            }
            else
            {
                if($key['ACCOUNT_CATEGORY_CODE'] == '9')
                {
                    $amount = round($key['AMOUNT'],2)*-1;
                }
                else
                {
                    $amount = round($key['AMOUNT'],2);
                }
            }
  
            
            $dt_exsis = $this-&gt;ledger_model-&gt;cek_data_coa_exsis($key['COA_CODE'],$modul,$ID_USER);
            if(empty($dt_exsis['id']))
            {
                //TRYINSERTINGBATCH
                // $datainsert[] = '('.$key['COA_CODE'].','.$amount.','.$ID_USER.',"'.$modul.'")';
                // $test = $key['COA_CODE'];
  
                $datainput = array(
                        'COA_CODE' =&gt; $key['COA_CODE'],
                        'AMOUNT' =&gt; $amount,
                        'MODUL' =&gt; $modul,
                        'USER_ID' =&gt; $ID_USER
                        );
                        
                $this-&gt;ledger_model-&gt;save_rows_to_table($datainput,'finance_lapkue_temp');
            }
            else
            {
                $amount_fix = $amount + $dt_exsis['AMOUNT'];
                $data=array(
                  'AMOUNT' =&gt; $amount_fix
                );
                $this-&gt;ledger_model-&gt;edit_rows_to_table_where($data,'finance_lapkue_temp','id',$dt_exsis['id']);
                // $q = "UPDATE finance_lapkue_temp set AMOUNT = '$amount_fix' where id = '".$dt_exsis['id']."'";
                // $this-&gt;db-&gt;query($q);
            }
            // $data_amount[$key['COA_CODE']] += $amount;
        }
       ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>if i using this code, the proccess so slow</p>