0

Possible Duplicate:
MySQL don't want to store unicode character

I writing a bbs php code, user reply something with some special unicode word, and I find my mysql code can not work. var_dump it, the sql look like:

I use a Mac mysql client Sequel Pro, run this code, it said that:

No errors;0 rows affected.

But when remove the word "kiss", it said that:

No errors;1 rows affected.

Do you know why? And how I solve it?

Please notice, this user input is already process by mysql_real_escape_string.

Community
  • 1
  • 1
Tinyfool
  • 1,460
  • 2
  • 18
  • 40
  • Have you tried to use `mysql_set_charset('utf8');` after you connected to the db? – some Dec 12 '11 at 04:55
  • already mysql_set_charset('utf8'); ... – Tinyfool Dec 12 '11 at 04:59
  • Also try `mysql_query("SET NAMES utf8");` – some Dec 12 '11 at 05:00
  • already mysql_query("SET NAMES utf8"); – Tinyfool Dec 12 '11 at 05:01
  • Ok. What codepoint has the kiss? Is it outside of the BMP? http://stackoverflow.com/questions/2692188/mysql-dont-want-to-store-unicode-character – some Dec 12 '11 at 05:07
  • Yes, it is like this. but I do not want upgrade to mysql 5.5, and find some way now. – Tinyfool Dec 12 '11 at 05:19
  • Well, as @some doesn't seem to be willing to write it as an answer, at least it have to be marked as a duplicate. However, I doubt it will get enough votes, so it would be nice to add the link to the question manually. – Your Common Sense Dec 12 '11 at 07:11
  • @Col. Shrapnel: It's not that I didn't want to write an answer, but more that I needed more information. Now it's clear that it's a duplicate. – some Dec 12 '11 at 10:27

1 Answers1

-2

Escape query string first then feed it to SQL statement. PHP has mysql_real_escape_string.

If mysql_real_escape_string doesn't work, then you may want to use prepare statements instead to avoid the issue entirely, like so:

$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

The above example is quoted from PHP document.

edwardw
  • 12,652
  • 3
  • 40
  • 51