English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

Because apostrophe has special meaning in MySQL; MySQL treats it as a single quote. So when you run a query like this:

INSERT INTO myTable SET lastName = 'O'Connell';

MySQL thinks that the apostrophe after the "O" is a closing single quote, and "Connell'" is the next SQL clause, which, of course, it isn't; hence, the error.

To prevent this from happening, you must escape the apostrophe with a backward slash:

INSERT INTO myTable SET lastName = 'O\'Connell';

2007-06-22 05:16:05 · answer #1 · answered by NC 7 · 1 0

if you are using php to enter the data into the mysql database all you need to do is use the addslashes function and it will escape all the ' in your variable...
addslashes($myString);

2007-06-22 05:25:47 · answer #2 · answered by sheepbalz 3 · 0 0

They indicate a string is enclosed. If you want to embed, use:

\' (\ is the escape character telling it to take the next character literally).

2007-06-22 05:17:10 · answer #3 · answered by John K 3 · 0 0

fedest.com, questions and answers