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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:36:03+00:00 2026-06-09T13:36:03+00:00

SQL parameterization is a hot topic nowadays, and for a good reason , but

  • 0

SQL parameterization is a hot topic nowadays, and for a good reason, but does it really do anything besides escaping decently?

I could imagine a parameterization engine simply making sure the data is decently escaped before inserting it into the query string, but is that really all it does? It would make more sense to do something differently in the connection, e.g. like this:

> Sent data. Formatting: length + space + payload
< Received data
-----
> 69 SELECT * FROM `users` WHERE `username` LIKE ? AND `creation_date` > ?
< Ok. Send parameter 1.
> 4 joe%
< Ok. Send parameter 2.
> 1 0
< Ok. Query result: [...]

This way would simply eliminate the issue of SQL injections, so you wouldn’t have to avoid them through escaping. The only other way I can think of how parameterization might work, is by escaping the parameters:

// $params would usually be an argument, not in the code like this
$params = ['joe%', 0];

// Escape the values
foreach ($params as $key=>$value)
    $params[$key] = mysql_real_escape_string($value);

// Foreach questionmark in the $query_string (another argument of the function),
// replace it with the escaped value.
$n = 0;
while ($pos = strpos($query_string, "?") !== false && $n < count($params)) {
    // If it's numeric, don't use quotes around it.
    $param = is_numeric($params[$n]) ? $params[$n] : "'" . $params[$n] . "'";
    // Update the query string with the replaced question mark
    $query_string = substr($query_string, 0, $pos) //or $pos-1? It's pseudocode...
                  . $param
                  . substr($query_string, $pos + 1);
    $n++;

If the latter is the case, I’m not going to switch my sites to parameterization just yet. It has no advantage that I can see, it’s just another strong vs weak variable typing discussion. Strong typing may catch more errors in compiletime, but it doesn’t really make anything possible that would be hard to do otherwise – same with this parameterization. (Please correct me if I’m wrong!)


Update:

  • I knew this would depend on the SQL server (and also on the client, but I assume the client uses the best possible techniques), but mostly I had MySQL in mind. Answers concerning other databases are (and were) also welcome though.
  • As far as I understand the answers, parameterization does indeed do more than simply escaping the data. It is really sent to the server in a parameterized way, so with variables separated and not as a single query string.
  • This also enables the server to store and reuse the query with different parameters, which provides better performance.

Did I get everything? One thing I’m still curious about is whether MySQL has these features, and if query reusage is automatically done (or if not, how this can be done).

Also, please comment when anyone reads this update. I’m not sure if it bumps the question or something…

Thanks!

  • 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-09T13:36:04+00:00Added an answer on June 9, 2026 at 1:36 pm

    I’m sure that the way that your command and parameters are handled will vary depending on the particular database engine and client library.

    However, speaking from experience with SQL Server, I can tell you that parameters are preserved when sending commands using ADO.NET. They are not folded into the statement. For example, if you use SQL Profiler, you’ll see a remote procedure call like:

    exec sp_executesql N'INSERT INTO Test (Col1) VALUES (@p0)',N'@p0 nvarchar(4000)',@p0=N'p1'
    

    Keep in mind that there are other benefits to parameterization besides preventing SQL injection. For example, the query engine has a better chance of reusing query plans for parameterized queries because the statement is always the same (just the parameter values change).

    In response to update:
    Query parameterization is so common I would expect MySQL (and really any database engine) to handle it similarly.

    Based on the MySQL protocol documentation, it looks like prepared statements are handled using COM_PREPARE and COM_EXECUTE packets, which do support separate parameters in binary format. It’s not clear if all parameterized statements will be prepared, but it does look like unprepared statements are handled by COM_QUERY which has no mention of parameter support.

    When in doubt: test. If you really want to know what’s sent over the wire, use a network protocol analyzer like Wireshark and look at the packets.

    Regardless of how it’s handled internally and any optimizations it may or may not currently provide for a given engine, there’s very little (nothing?) to gain from not using parameters.

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

Sidebar

Related Questions

SQL Server 2008: Sorry for the possibly non-informative title but I'm not sure quite
SQL Server uses binary tree with intermediate and leaf node for search but how
SQL Server uses .mdf for data files and .ldf for log files, but what
Sql Server 2008 does not natively support hit highlighting in its FTS functionality, and
SQL Server seems to have really terrific tools and features, enough to make me
SQL/PHP query works in PHPmyAdmin but not the site. I notice that many have
SQL Server 2008 I have a query with several local variables that does some
SQL: SELECT COUNT(*) FROM bb_posts post LEFT JOIN bb_topics topic ON topic.topic_id = post.topic_id
SQL is not my forte, but I'm working on it - thank you for
SQL Server 2000 doesn't seem to support the xml based .xlsx file types. Besides

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.