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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:50:28+00:00 2026-06-13T15:50:28+00:00

I want to insert many thousand records and I need this to be fast.

  • 0

I want to insert many thousand records and I need this to be fast. I read a lot about this issue so I decided to drop my old approach (mysql_connect) and use prepare statements and mysqli. So In order to test the speed of this I write the following.

function load_data2db($sms_id){
$mysqli = new mysqli('localhost', 'root', 'cr3at1ve', 'tmp-clicknsend');
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}


// Create statement object
$stmt = $mysqli->stmt_init();
if ($stmt = $mysqli->prepare("INSERT INTO isec_test (sms_id, status,msgid,prmsgid,mob,sms_history_id) values (?, ?, ?, ?, ?, ?)")) {


        /* Bind our params */
        $stmt->bind_param('ssssss',$sms_id,$status,$msgid,$prmsgid,$mob,$sms_history_id);

    for($i=0;$i<100000;$i++)
    {
        /* Set our params */
        $sms_id = "110";
        $status = "OK";
        $msgid  = "msgid";
        $prmsgid = "100-0";
        $mob = "306974386068";
        $sms_history_id = 102;

        /* Execute the prepared Statement */
        $stmt->execute();
    }


        /* Close the statement */
        $stmt->close();
}
else {
        /* Error */
        printf("Prepared Statement Error: %s\n", $mysqli->error);
}
}

load_data2db(10);

Then I did the same with the old way ( looping and inserting one by one)

include("mysql_connect.php");
 for($i=0;$i<100000;$i++)
    {
    $query = "INSERT INTO isec_test(sms_id,status,msgid) values ('1','OK','123-123')";
    $query = @mysql_query($query);
    }
mysql_close($dbc);

I made a lot of tests and always the simple mysql way was 1 sec faster. So I am puzzled. What can I do? Use LOAD DATA?

  • 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-06-13T15:50:29+00:00Added an answer on June 13, 2026 at 3:50 pm

    I would recommend you use LOAD DATA LOCAL INFILE unless you need to do some processing per row as you insert.

    It’s often recommended that preparing an SQL statement and binding parameters is faster on the database side, because it eliminates the need to re-parse the SQL query thousands of times.

    But the PHP extension itself contains a bit of code that needs to run on the application side. The mysqli extension may be more complex and thus run with slightly more overhead than the old mysql extension for repetitive operations.

    In PHP, the overhead of a single function call can be noticeable if you repeat it enough times in a loop. I’ve had people tell me there’s a measurable difference between these two statements:

    $x = (int) '123';
    $x = intval('123');
    

    The second line is a function call, so it’s slower (though by a very small margin).

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

Sidebar

Related Questions

I need to insert many entities into the database via Hibernate. So, I want
I want to insert n records into a single table. There may be many
I want to insert many rows in front of the last row in a
I want to insert this HTML element in some pages: <a download=somedata.csv id=downloadLink href=data:application/csv;charset=utf-8,Col1%2CCol2%2CCol3%0AVal1%2CVal2%2CVal3%0AVal11%2CVal22%2CVal33%0AVal111%2CVal222%2CVal333
I have a big txt file ,with many strings ,say string-I-want-to-change,now I need to
I have to insert many product value records into an Oracle table. I get
I want to insert some data into a many to many field. I 'm
I want to make many inserts in a single SQL statement, pretty much like
I want insert a custom snippet into an XML file from code within an
I want to insert a record into a MySQL database table from a formulaire.

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.