How do I escape special characters in MySQL? -


for example:

select * tablename fields "%string "hi"  %"; 

error:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'hi" "' @ line 1

how build query?

the information provided in answer can lead insecure programming practices.

the information provided here depends highly on mysql configuration, including (but not limited to) program version, database client , character-encoding used.

see http://dev.mysql.com/doc/refman/5.0/en/string-literals.html

 mysql recognizes following escape sequences. \0     ascii nul (0x00) character. \'     single quote (“'”) character. \"     double quote (“"”) character. \b     backspace character. \n     newline (linefeed) character. \r     carriage return character. \t     tab character. \z     ascii 26 (control-z). see note following table. \\     backslash (“\”) character. \%     “%” character. see note following table. \_     “_” character. see note following table. 

so need

select * tablename fields "%string \"hi\" %"; 

although bill karwin notes below, using double quotes string delimiters isn't standard sql, it's practice use single quotes. simplifies things:

select * tablename fields '%string "hi" %'; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

android - Go back to previous fragment -