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

  • SEARCH
  • Home
  • 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 7513835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:18:30+00:00 2026-05-30T00:18:30+00:00

I have a CSV file with around 1.8million rows. I need to insert them

  • 0

I have a CSV file with around 1.8million rows. I need to insert them into a MySQL table from my PHP script. I am inserting the values in batches of 10,000.
The scripts run for very long time and crashes after inserting 80-95 batches. I have tried mysql_unbuffered_query() also but of no use.

if ($fp) {
        $batch = 1;
        $row_count = 1;
        $bucket_counter = 1;
        $mobile_numbers = array();
        $row_count_for_DB_write = 0;
        foreach ($campaign_numbers as $value) {
            $number = array($value);
            fputcsv($fp, $number);
            $row_count_for_DB_write++;
            $value_row = new stdClass();
            $value_row->number = $value;
            $value_row->bucket_number = $bucket_counter;
            $mobile_numbers[] = $value_row;
            if ($row_count == $bucket_size && $bucket_counter < $bucket_count) {
                $bucket_counter++;
                $row_count = 1;
                fclose($fp);
                $fp = fopen($directory . "/cn_$bucket_counter.csv", 'w');
                $logger->debug('Created csv file : ' . $directory . '/cn_$bucket_counter.csv');
            }

            if ($row_count_for_DB_write == CONSTANTS::BATCH_SIZE) {
                $logger->debug($batch." Batch insert starting at: ".date('d-m-Y_H-i-s', time()));
                $insert_count = $data_service->add_to_mobile_numbers_table($mobile_numbers_table, $mobile_numbers);
                $batch++;
                $logger->debug("Batch insert ending at: ".date('d-m-Y_H-i-s', time()));
                $row_count_for_DB_write = 1;
                unset($mobile_numbers);
                $mobile_numbers = array();
            }
            $row_count++;
        }
    }
    fclose($fp);
    $data_service->add_to_mobile_numbers_table($mobile_numbers_table, $mobile_numbers);
    $zip_file = "/$directory_name.zip";
    $logger->debug('Creating zipped file');
    Util::create_zip(Util::get_list_of_files($directory), $directory . $zip_file);
  • 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-30T00:18:32+00:00Added an answer on May 30, 2026 at 12:18 am

    Following steps solved this issue:

    • Change table engine from InnoDB to MyISAM

    • disable the keys

    • insert data

    • re-enable the keys

    • 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 which contains around 1200 rows. I was trying to
I am trying to create a CSV file from a dynamically generated table.I have
When importing a CSV file into Excel, it only strips the double-quotes from the
I have a datagrid in a WPF populated from a csv file. This is
How would I go around creating a MYSQL table schema inspecting an Excel(or CSV)
I have a simple csv file with around 20K+ values separated by commas. When
I am using PHP to expose vehicle GPS data from a CSV file. This
We have split up a CSV file into individual lines and those lines have
I'm working with a CSV file in python, which will have ~100,000 rows when
I'm having troubles with a PHP script that imports csv files into MongoDB. There's

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.