28

I have encountered some websites that when I used -- to comment the rest of the query it didn't work, but when I tried --+ it worked.

In the MySQL official documentation there is no such thing as --+ and we only have -- and two other ways.

Why does this happen (in detail)? I want to know exactly why this works sometimes and -- doesn't, and why there is no --+ for comments in the MySQL man page?

Anders
  • 64,406
  • 24
  • 178
  • 215
Richard Jones
  • 497
  • 1
  • 6
  • 9

1 Answers1

59

From the documentation:

From a -- sequence to the end of the line. In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace or control character (such as a space, tab, newline, and so on). This syntax differs slightly from standard SQL comment syntax, as discussed in Section 1.8.2.4, “'--' as the Start of a Comment”.

(emphasis mine)

Many URL decoders treat + as a space.

AndrolGenhald
  • 15,436
  • 5
  • 45
  • 50
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/84883/discussion-on-answer-by-androlgenhald-why-should-we-sometimes-use-instead-of). – Rory Alsop Oct 24 '18 at 18:44