What happened:
- you had utf8-encoded data (good)
SET NAMES latin1
was in effect (default, but wrong)
- the column was declared
CHARACTER SET latin1
(default, but wrong)
As you INSERTed
the data, it was converted to latin1, which does not have values for Arabic (Kurdish/Farsi/etc) characters, so question marks replaced them.
The cure (for future INSERTs
):
- utf8-encoded data (good)
mysqli_set_charset('utf8')
(or whatever your client needs for establishing the CHARACTER SET
)
- check that the column(s) and/or table default are
CHARACTER SET utf8
- If you are displaying on a web page,
<meta...utf8>
should be near the top.
The discussion above is about CHARACTER SET
, the encoding of characters. Now for a tip on COLLATION
, which is used for comparing and sorting.
To double check that the data is stored correctly, do
SELECT col, HEX(col)...
.
هرچوون
should come back D987E2808CD8B1DA86D988D988D986
Arabic characters in utf8 have hex of D8xx or D9xx.
(utf8mb4
works just as well as utf8
; either works for Arabic.)
Bad news: The data that was inserted and turned into '???' cannot be recovered.