title: php : csv import to multiple table is taking too long
body: <p>i am using csv importer library to load bulk of products into mysql database with codeigniter. csv file has some column names from one table like name, price and some column names from another table like categories. it inserts name and price to first table and categories will be inserted after we got id from first table, so category will go with id of the product. but this is taking too long to process the csv file (1000 entries = 2 minutes). the code i have put is</p>
  
  <pre><code>$csv_file_data = $this-&gt;csvimport-&gt;get_array($_FILES['csv']['tmp_name']);
  foreach ($csv_file_data as $csv_data) {
       $required = array(
                  'name' =&gt; $csv_data['name'],
                  'price' =&gt; $csv_data['price']
       );
       foreach ($required as $key =&gt; $value) {
                  $this-&gt;db-&gt;set($key, $value);
       }
       $categories= array();
       foreach ($csv_data as $key =&gt; $value) {
                  if(strstr($key, 'categories')) {
                      $category = explode('|', $value);
                      for($i = 0; $i &lt; sizeof($category); $i++) {
                          array_push($categories, $category[$i]);
                      }
                  }
       }
       $this-&gt;db-&gt;insert('first_table');
       $id = $this-&gt;db-&gt;insert_id();
  
       foreach ($categories as $metatag) {
                      $this-&gt;db-&gt;set('productid', $id);
                      $this-&gt;db-&gt;set('category', $metatag);
                      $this-&gt;db-&gt;insert('second_table');
       }
  }
  </code></pre>
  
  <p>but it is taking too long to process only 1000 entries, how to optimize this to process 5000 entries in less than 20-30 seconds ?</p>