php - Stored non-English characters, got '?????' - MySQL Character Set issue -
my site working on in farsi , text being displayed ????? (question marks). changed collation of db tables utf8_general_ci still shows ???
i ran following script change tables did not work well.
i want know doing wrong
<?php // connection mysql_connect("mysql.ord1-1.websitesettings.com","user_name","pass"); mysql_select_db("895923_masihiat"); // convert code $res = mysql_query("show tables"); while ($row = mysql_fetch_array($res)) { foreach ($row $key => $table) { mysql_query("alter table " . $table . " convert character set utf8 collate utf8_unicode_ci"); echo $key . " => " . $table . " converted<br />"; } } ?>
bad news. first, double check:
select col, hex(col)...
to see in table. if hex shows 3f
, data gone. correctly stored, dal
character should hex d8af
; hah
hex d8ad
.
what happened:
- you had utf8-encoded data (good)
set names latin1
in effect (default, wrong)- the column declared
character set latin1
(default, wrong)
as inserted
data, converted latin1, not have values farsi characters, question marks replaced them.
the cure (for future `inserts):
- recode application using mysqli_* interface instead of deprecated mysql_* interface.
- utf8-encoded data (good)
- mysqli_set_charset('utf8')
- check column(s) and/or table default
character set utf8
- if displaying on web page,
<meta...utf8>
should near top.
the discussion above character set
, encoding of characters. tip on collation
, used comparing , sorting.
if want these treated equal: 'بِسْمِ' = 'بسم', use utf8_unicode_ci (instead of utf8_general_ci) collation
.
Comments
Post a Comment