Possible Duplicate:
Today, mysql_real_escape_string() is escaping single quotes AND double quotes
I understand that single quotes and backslash have special meaning so they need to be escaped if we want them to be interpreted for their literal meaning.
As far as I understand , double quotes are not allowed in mysql queries to represent strings(if this assumption is correct, is this the only reason to escape them ?) and we should use single quotes instead to represent strings.
And what about NULL? Looking for specific examples to understand why double quotes and NULL need to be escaped.
Just to add, I’ve already searched here on stackoverflow and I see most examples refer to single quotes which I already understand… But I need to understand the reasoning behind double quotes and I cannot find any examples for that…
In default mode, MySQL allows for string literals to be enclosed in single quotes OR in double quotes.
For compatibility with other DBMS, and just in case MySQL mode is set to
ANSI_QUOTES, most SQL authors use single quotes to specify string literals. There’s really no advantage to using double quotes. (And why write a query in a way that will cause the query to be “broken” when someone changes a variable in their MySQL server session.)So, the short answer is that double quotes do not need to be escaped in all cases, e.g.
They do need to be escaped in some cases:
But it doesn’t hurt to escape the double quotes in any case: