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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:32:38+00:00 2026-06-07T20:32:38+00:00

I have heard that using PREPARE and EXECUTE in a SQL statement will sanitize

  • 0

I have heard that using PREPARE and EXECUTE in a SQL statement will sanitize user-supplied data into something incapable of SQL injection. Is this true?

My original query is this:

$query = 
"SELECT * FROM sales_orders 
WHERE ksisoldby ILIKE '".$user."'";

This is my best guess for changing it to a prepare/execute statement:

 <?php
$id = $_POST['id'];
$search = $_POST['user_supplied_search_term'];

PREPARE search_query_function (varchar, varchar) AS

SELECT * FROM sales_orders 
WHERE ksisoldby ILIKE '$1'";

EXECUTE search_query_function($id, $search);
?>

Is this written/invoked correctly? There are also some built in php objects (PDO) that I have read about. Should I be using those instead or in conjunction? Thanks for help on this sort of broad question.

  • 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-07T20:32:40+00:00Added an answer on June 7, 2026 at 8:32 pm

    You incorporate prepare() and execute() in PHP by using prepared statements, which are available when you use PDO. This extensions is responsible for creating the appropriate PREPARE and EXECUTE statements for your database according to the database driver you have selected.

    Here is an example adapted from the PHP manual using prepare() and execute().

    $sth = $dbh->prepare('SELECT * FROM sales_orders 
        WHERE ksisoldby ILIKE ?');
    $sth->execute( array( $_POST['user_supplied_search_term']));
    

    This will take care of the parameter escaping for you and create an SQL statement similar to:

    SELECT * FROM sales_orders 
        WHERE ksisoldby ILIKE 'something'
    

    So you need to adapt the above code to include your SQL statement within the call to prepare(), which requires you to add placeholders to where you want your parameters to be included. Then you call execute(), which will add in the values passed to it.

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

Sidebar

Related Questions

I have heard that in C++, using an accessor ( get...() ) in a
I'm considering using JRuby on App Engine but have heard that Juby app on
I have heard that Linq query write once can be run on SQL and
I am developing a MySQL Web App using ASP.net and I have heard that
I have heard that I should avoid using 'order by rand()', but I really
I have heard that using exception trapping is not a recommended practice for number
I have heard that using static member objects is not a very good practice.
I have heard a comment that using a DDL script for a database installation
I have an NSIS installer that has the start menu folders hard-coded using this
I have heard that when dealing with mutexes, the necessary memory barriers are handled

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.