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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:23:39+00:00 2026-06-08T07:23:39+00:00

I was always wondering if it is good practice to bind entire list of

  • 0

I was always wondering if it is good practice to bind entire list of values. For example I have to following query:

INSERT INTO messages 
  (thread_id,message,from_id,to_id,to_viewed,notified,from_deleted,to_deleted,created)
  SELECT :threadId,:msg,:fromId,:toId,0,0,0,0,:createdTime FROM messages 
    WHERE thread_id = :threadId AND to_id=:toId LIMIT 1

In this case would have any sense to bind also notified, from_deleted and to_deleted fields since this is static value, always 0 when inserting new msg?


I need to modify my question. I know that for security reason there is not reason to bind also fields/values that are not generated from user. In my case not reason to bind fileds notified, from_deleted and to_deleted because they are always 0. But my real question is should I bind those fields for other reasons (cache). Will mysql cache entire query statement or only binded parms?

  • 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-08T07:23:40+00:00Added an answer on June 8, 2026 at 7:23 am

    It is really only necessary to as you say bind the parameters (a prepared query) of variables that are from an external source (which you should also strip out html characters, scripts). When you do a prepared query PDO will convert quotes to prevent a sql injection. You can just put your static variables straight into the query because you (developer) know that it’s safe for a 0 or 1 to be looked for or even some static string for that matter. The rest is just a matter of having a syntactically correct query.

    You can run this query to insert a test row by using sequelpro, phpmyadmin, the mysql cli or any other sql utility (assuming you are running mysql)

    INSERT INTO messages 
      (thread_id,message,from_id,to_id,to_viewed,notified,from_deleted,to_deleted,created)
      VALUES (1, 'Blah', 1, 2, 3, 0, 0, 0, '2012-07-21');
    

    PDO Example

    try {
        $dbh = new PDO($dsn, $user, $password);
        $sth = $dbh->prepare('SELECT * FROM messages WHERE thread_id = :threadId AND to_id=:toId LIMIT 1');
        $sth->execute(array(':threadId' => $id, ':toId' => $to_id));
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering what the recommended practice is for importing namespaces. Are you always better
I am wondering if there is a good-performing query to select distinct dates (ignoring
Im wondering if its good practice to pass-by-reference when you are only reading a
I was wondering if it were a good idea to use an initializer list
I was always wondering how does the login operation performs so quickly when I'm
This is likely a stupid question but I always find myself wondering which is
I was wondering if it is always necessary to use something like is_array() before
I am wondering if the aspnet_Users table is always sorted (by UserName) even if
I've always wondered about this, and now a client is wondering whether it's feasable:
I always thought that you could use OR in a LIKE statment to query

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.