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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:00:53+00:00 2026-06-10T12:00:53+00:00

If you will consider the following table table_A (id (PK), value1, value2) If I

  • 0

If you will consider the following table

table_A (id (PK), value1, value2)

If I want to insert a set of data, for example: (1,5), (1,3), (3,5)

I could perform a query such as :

INSERT INTO table_A (value1, value2) VALUES (1,5), (1,3), (3,5)

which would work. However, I am told prepared statements would be better. Looking into prepared statements it seems I would have to do something like this

$stmt = $dbh->prepare("INSERT INTO table_A (value1, value2) VALUES (?, ?)");
$stmt->bindParam(1, $value1);
$stmt->bindParam(2, $value2);

//for each set of values
$value1 = 1;
$value2 = 5;
$stmt->execute();

my question is, how can a prepared statement be better (performance wise) than the first method? One is a single query, the other involves several executions of the same query. Does the first query get compiled into three separate queries or something?

  • 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-10T12:00:55+00:00Added an answer on June 10, 2026 at 12:00 pm

    The prepared statement by itself is not going to be faster when you insert only once. However, if you need to run the same inserts multiple times, you will save on the time it takes to parse the query and prepare the query plan. The prepared statement insert will be parsed once, the plan for it will be cached, and then reused for all subsequent insertions. The statement with multiple embedded values, on the other hand, will need to be re-processed every time you run a new one, slowing the process down.

    On the other hand, network roundtrips are slow as well. It may be slower to do an extra roundtrip than to parse and prepare a query plan, so you should profile before making a decision one way or the other.

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

Sidebar

Related Questions

Consider the following data set in a book table (group_id, title, check_out_date): > 1
Consider the following criteria query: var x = SomeCriteria.AddOrder(new Order(Name, true)).List(); This will order
I need help with a query. Consider the following table: I need to select
Consider the following query: SELECT operation, [...] FROM tableName The operation field will retrieve
consider the following table create table sample(id, name, numeric, qno, ans1,ans2,ans3) sample data 1,
Please consider the following table structure and data: +--------------------+-------------+ | venue_name | listed_by |
I have a parent child relationship stored in a table consider the following example
Consider the following table: +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key |
Please consider the following scripts. Create Table: IF OBJECT_ID('Colortable') IS NOT NULL DROP TABLE
Consider the following table: People FirstName nvarchar(50) LastName nvarchar(50) Let's assume for the moment

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.