Database Reference
In-Depth Information
You should also ensure that the character set used by your display device matches what
you use for MySQL. Otherwise, even with MySQL handling the data properly, it might
display as garbage. Suppose that you use the mysql program in a terminal window and
that you configure MySQL to use utf8 and store utf8 -encoded Japanese data. If you set
your terminal window to use euc-jp encoding, that is also Japanese, but its encoding
for Japanese characters differs from utf8 , so the data will not display as you expect. (If
you use autodetection, this should not be an issue.)
In web contexts, you can include a character-set encoding in the Content-Type: header
that precedes the web page content. See Recipe 18.1 .
5.4. Writing String Literals
Problem
You need to write literal strings in SQL statements.
Solution
Learn the syntax rules that govern string values.
Discussion
You can write strings several ways:
• Enclose the text of the string within single quotes or double quotes:
'my string'
"my string"
When the ANSI_QUOTES SQL mode is enabled, you cannot use double quotes for
quoting strings: the server interprets double quote as the quoting character for
identifiers such as table or column names, and not for strings (see Recipe 2.6 ). If
you adopt the convention of always writing quoted strings using single quotes,
MySQL interprets them as strings and not as identifiers regardless of the AN
SI_QUOTES setting.
• Use hexadecimal notation. Each pair of hex digits produces one byte of the string.
abcd can be written using any of these formats:
0x61626364
X'61626364'
x'61626364'
MySQL treats strings written using hex notation as binary strings. Not coinciden‐
tally, it's common for applications to use hex strings when constructing SQL state‐
ments that refer to binary values:
Search WWH ::




Custom Search