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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:00+00:00 2026-05-26T16:03:00+00:00

I have an array of information about links I’ve found on a webpage in

  • 0

I have an array of information about links I’ve found on a webpage in a PHP script.

Each link needs to be inserted into a MySQL myisam table.

Right now, I loop through the array and run an insert query for each link.

Is there a more appropriate way to do this so that I’m using MySQL more efficiently?

  • 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-26T16:03:01+00:00Added an answer on May 26, 2026 at 4:03 pm

    You can insert multiple values in a single statement using the following syntax:

    INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
    

    see Section 12.2.5 of the MySQL manual

    This is especially advisable if the MySQL server is on a different host than the PHP server: in the example above, you need only a single network roundtrip rather than three.

    If network latency is not an issue (if the MySQL server runs on the same server as PHP), use prepared statements like this:

    $dbh = new PDO("mysql:host=127.0.0.1;port=3306;dbname=test", "root", "");
    
    $sth = $dbh->prepare("INSERT INTO links(title, href) VALUES(:title, :href);");
    
    while ($link = getNextLink()) {
        $sth->execute( array( "title" => $link->title, "href" => $link->href ) );
    }
    

    Prepared statements are slightly faster when executed repeatedly, because the MySQL server has to parse the SQL and run the query planner/optimizer only once.

    If the table has indices, you can disable them before inserting and enable them again after inserting, this makes inserting rows faster because the indices don’t have to be updated after every insert (only possible for MyISAM, see section 12.1.7 of the Mysql manual):

    ALTER TABLE links DISABLE KEYS
    -- insert rows
    ALTER TABLE links ENABLE KEYS
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that shows information from my database. Each array has an
I have this array with information string[] aInfo; // Contains information about this person
I have an array of arrays - information about selection in Excel using VSTO,
I have constructed a array that gets the information from checkboxes. This is working
I have a listview connected to a custom array adapter. This list shows information
I found this script on about.com which I'm trying to learn from on how
I found this script on about.com which I'm trying to learn from on how
A text file holds information about a softball team. Each line has data arranged
I want to have a List or Array of some sort, storing this information
I have to create a function which gets 5 parameters representing information about 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.