Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6743279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:56:33+00:00 2026-05-26T11:56:33+00:00

I have a csv file that has roughly 100K entries I need to process

  • 0

I have a csv file that has roughly 100K entries I need to process and insert into a data base.

Previously it was very slow because it makes an SQL call for every entry. I do this though because if I try to build 1 single query to do this I will run out of memory.

I migrated to a new server and now I get an error every time I run it:

SQL Error : 2006 MySQL server has gone away

I am not sure but think this is just happening because how inefficient my code is.

What can I do to make it perform better and not get the error?

Here is the code:

//empty table before saving new feed
$model->query('TRUNCATE TABLE diamonds');

$fp = fopen($this->file,'r');

while (!feof($fp)) 
{
    $diamond = fgetcsv($fp);

    //skip the first line
    if(!empty($firstline))
    {
        $firstline = true;
        continue;   
    }

    if(empty($diamond[17]))
    {
        //no price -- skip it
        continue;
    }

    $data = array(
        'seller'             => $diamond[0],                             
        'rapnet_seller_code' => $diamond[1],                         
        'shape'              => $diamond[2],
        'carat'              => $diamond[3],
        'color'              => $diamond[4],
        'fancy_color'        => $diamond[5],
        'fancy_intensity'    => $diamond[6],
        'clarity'            => empty($diamond[8]) ? 'I1' : $diamond[8],
        'cut'                => empty($diamond[9]) ? 'Fair' : $diamond[9],
        'stock_num'          => $diamond[16],
        'rapnet_price'       => $diamond[17],
        'rapnet_discount'    => empty($diamond[18]) ? 0 : $diamond[18],
        'cert'               => $diamond[14],
        'city'               => $diamond[26],
        'state'              => $diamond[27],
        'cert_image'         => $diamond[30],
        'rapnet_lot'         => $diamond[31]
    );

    $measurements = $diamond[13];
    $measurements = strtolower($measurements);
    $measurements = str_replace('x','-',$measurements);
    $mm = explode('-',$measurements);

    $data['mm_width'] = empty($mm[0]) ? 0 : $mm[0];
    $data['mm_length'] = empty($mm[1]) ? 0 : $mm[1];
    $data['mm_depth'] = empty($mm[2]) ? 0 : $mm[2];

    //create a new entry and save the data to it.
    $model->create();
    $model->save($data);

}
fclose($fp);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:56:34+00:00Added an answer on May 26, 2026 at 11:56 am

    You’re probably exceeding MySQL’s max_allowed_packet setting, which sets a hard limit (in bytes) on how long a query string can be. There’s nothing wrong with doing multi-value inserts, but 100k of them is definitely pushing things.

    Instead of doing all 100k at once, try doing 1000 in a loop. You’re still reducing total query count (down from 100k to just 1000), so it’s still a net gain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .csv file that has data in a column, I need that
I have a CSV file that has rows, where data for some columns only
I have a simple .csv file that has that I want to extract data
I have a data file in CSV format that has the some data like
I have data from a CSV file that's already loaded into memory. So I
I have a CSV file that has data like this 15,I,2,41301888,BYRNESS RAW,,BYRNESS VILLAGE,NORTHUMBERLAND,ENG 11,I,3,41350101,2,2935,2,2008-01-09,1,8,0,2003-02-01,,2009-12-22,2003-02-11,377016.00,601912.00,377105.00,602354.00,10
I have a CSV file that has only 1 column, but has close to
In short, I have a 20,000,000 line csv file that has different row lengths.
I have a CSV data file with rows that may have lots of columns
I have a CSV of file of data that I can load in R

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.