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 3324164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:23:21+00:00 2026-05-17T23:23:21+00:00

Background I basically have an array, this array has the following format Array (

  • 0

Background

I basically have an array,

this array has the following format

Array
(
    [0] => Array
        (
            [co_id] => 1
            [co_fname] => First
            [co_lname] => Last
            [co_company] => Company
            [co_address] => Address
            [co_ddi] => ddinumber
            [co_mobile] => mobilenumber
            [co_fax] => 
            [co_email] => email@example.com
            [co_usms] => 1
            [co_ufax] => 0
            [co_uemail] => 1
            [a_id] => 3
        )
)

I am looping over this array and am creating some insert statements.

There are three tables, Message_email, Message_fax, Message_sms.

If A contact has co_u(sms/fax/email) as 1 I add the contacts id, and the respective contact information(co_mobile/co_fax/co_email) to its respective array ($mobile/$fax/$sms).

The array’s information is then added to the tables.


Question

These arrays can get quite large (think 200k+ contacts).

Should I.

a) Create a single bulk insert statement.
b) Create several smaller bulk insert statements.
c) Do an insert statement for each contact.

Speed is good but not so much of an issue.
Reliability is the big one.

Matt

  • 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-17T23:23:21+00:00Added an answer on May 17, 2026 at 11:23 pm

    I typically do batches based upon the length of the SQL query. I will build out the query, appending each time until it reaches some easy length (10000 characters is a nice length), and then flush it to the server:

    $query = 'INSERT INTO FOO (values) VALUES ';
    $separator = '';
    $values = '';
    foreach ($rows as $row) {
        $values .= $separator . '('.$row.')';
        $separator = ', ';
        if (strlen($values) >= 10000) {
            query($query . $values);
            $values = '';
            $separator = '';
        }
    }
    if (!empty($values)) query($query . $values);
    

    It’s nice because it compensates for small inserts (int, int) and huge ones (int, text, text)… Plus, you don’t risk the query taking too long and timing out your connection (or blocking other users for too long). With my data sets, 10k characters seems like a sweet spot. Since MAX_PACKET is usally 1mb, you could go as high as 750k or so and still have plenty of room for error (depending on your dataset). But I’d rather use a bunch of smaller batches than one huge one…

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

Sidebar

Related Questions

I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I basically have this markup coming from my JSP. I add class in each
Basically I have a background image which is loaded while the rest of the
Basically I have this server app I built in vc#, and for some reason
Background: I have a little video playing app with a UI inspired by the
Background: At my company we are developing a bunch applications that are using the
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I am trying to create a copy of a business object I have
Background I work for a large organization which has thousands of MS Access applications
Background I have been asked by a client to create a picture of the

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.