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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:23:32+00:00 2026-06-13T06:23:32+00:00

I was explaining parametrization and its advantages to my friend recently, and he asked

  • 0

I was explaining parametrization and its advantages to my friend recently, and he asked how it was any better than mysqli_escape_string in terms of security. Specifically, can you think of any examples of SQL injection that would succeed despite the input strings being escaped (using mysqli_escape_string)?

UPDATE:

I apologise for not being clear enough in my original question. The general question being asked here is, is SQL injection possible despite escaping input strings?

  • 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-13T06:23:34+00:00Added an answer on June 13, 2026 at 6:23 am

    Updated answer

    The question was edited (after my answer was posted) to specifically target mysqli_escape_string, which is an alias of mysql_real_escape_string and therefore takes the connection encoding into account. This makes the original answer non-applicable anymore, but I ‘ve left it for completeness.

    The new answer, in short: mysqli_escape_string is as good security-wise as parameterized queries, provided you don’t shoot yourself in the foot.

    Specifically, what you must not do is highlighted in the giant warning on the PHP doc page:

    The character set must be set either at the server level, or with the
    API function mysqli_set_charset() for it to affect
    mysqli_real_escape_string().

    If you don’t heed this warning (i.e. if you change the character set with a direct SET NAMES query) and you change the character set from a single-byte encoding to a “convenient” (from the attacker’s perspective) multibyte encoding, you will have in effect emulated what the dumb mysql_escape_string does: attempt to escape characters without knowing which encoding the input is in.

    This situation leaves you potentially vulnerable to SQL injection as described by the original answer below.

    Important note: I remember reading somewhere that recent MySql versions have plugged this hole on their end (in the client libraries?), which means that you might be perfectly safe even if using SET NAMES to switch to a vulnerable multibyte encoding. But please don’t take my word for it.

    Original answer

    In contrast to mysql_real_escape_string, the bare mysql_escape_string does not take into account the connection encoding. This means that it assumes the input is in a single-byte encoding, when in fact it can legitimately be in a multibyte encoding.

    Some multibyte encodings have byte sequences that correspond to a single character where one of the bytes is the ASCII value of the single quote (0x27); if fed such a string, mysql_escape_string will happily “escape the quote”, which means substituting 0x27 with 0x5c 0x27. Depending on the encoding rules, this could result in mutating the multibyte character into another that includes the 0x5c and leaving the “remaining” 0x27 as a stand-alone single quote in the input. Voilà, you have injected an unescaped quote into the SQL.

    For more details see this blog post.

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

Sidebar

Related Questions

The question is self-explaining, how to create a tearoff menu using GTKAda? I can't
I will try explaining the problem in as much detail as I can, without
I was explaining to a friend a few days ago the concept or inheritance
Example code so I can start explaining this problem: <div style=z-index:5>5</div> <div style=z-index:2>2</div> <div
Is there a documentation explaining android Stagefright architecture? Can I get some pointers on
Hi I'm not very good at explaining this in the right terms but I'm
Recently while I was explaining the basic difference between pointers and references(in context of
I can't find one term for explaining the effect that I would to achieve
Consider the following article explaining hashtables / dictionaries in JavaScript: Can anyone recommend a
I have seen long articles explaining how floating point numbers can be stored and

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.