I am creating a MySQL Table, and one of column’s type is ENUM.
I have several different ENUM values. Some of them are two or more words, e.g. Hugo Boss.
Other ENUM values have an apostrophe in them, e.g. Men’s, or other characters, e.g. &.
My question is two part:
- It is ok to have one or more spaces in an
ENUMvalue (two words, or more)? - Are apostrophes, ampersands, and other such characters, allowed in
ENUMvalues? And if they are, how would I go about placing them?
Seems so:
Note: The warning means that I have used a value which was not allowed – I tried to insert 3, which is not defined as value for the
ENUM.So it works perfectly – as with any other strings in MySQL. You only have to take care that you treat them correctly – either as hex values, or use
mysql_real_escape_string()or prepared statements. This provides for correct communication of “critical” values such as\\,',"etc.For example, if I have a string which contains “3’4”, and I want to define it as a part of an enum, I create the query by putting one of
0x332734or'3\'4'to the appropriate place.'3\'4'is obtained as a result ofmysql_real_escape_string("3'4")in the used programming language.NUL characters are not allowed as
ENUMcomponents as they would be in data strings – the used string is terminated before, though.