1

I inserted some data from a letters field in database1.table1 to new_letters field in database2.table2 by using PHP, but all the values are changed to question marks like ????? ?????? ????? ??????? ?? ??? ???? ????? ????? in the new_letters field. Structure of the letters is (Type:longtext, Collation: utf8_general_ci), and the structure of the new_letters is (Type:mediumtext, Collation: utf8_unicode_ci). Also, I need to mention that even changing both collations to utf8_unicode_ci or utf8_general_ci did not solve the problem. Could you please let me know what is the problem?

Sami
  • 1,461
  • 1
  • 15
  • 36

2 Answers2

4

You need to make sure your collation and character sets are consistent. For instance, you have two different collations (utf8_general_ci and utf8_unicode_ci), so you should convert them both to the same collation. I believe UTF-8 supports Arabic letters.

So, CHARACTER SET utf8 and COLLATE utf8_general_ci

Alex W
  • 35,267
  • 10
  • 97
  • 106
  • I changed both fields to `utf8_general_ci` but there was no change, still all the same problem – Sami Apr 09 '14 at 16:20
  • Do I need to apply specific condition before the query execution? – Sami Apr 09 '14 at 16:22
  • 2
    @Apiah: you also need to make sure your phpmysql connection is set for utf8 as well. ALL stages of the entire process have to set for utf8, or you'll get mangled text. – Marc B Apr 09 '14 at 16:28
1

You need to make sure your entire chain from the connection, to the database, to the tables is all UTF8 clean. I have a detailed answer to a similar question here.

But in your case, check the actual MySQL server my.cnf file. The following would set the whole chain to UTF-8:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Community
  • 1
  • 1
Giacomo1968
  • 24,837
  • 11
  • 67
  • 96
  • 1
    thanks for your answer. I applied your settings to `my.cnf` file, but still there is no change, is there something else I'm missing? – Sami Apr 09 '14 at 16:57
  • 1
    I also added this to the top of my PHP file `mysqli_query($dbcon, "SET NAMES 'utf8'");` in addition to your settings in `my.conf` and now is working fine, – Sami Apr 09 '14 at 17:24
  • @Apiah: “I applied your settings to my.cnf file, but still there is no change” Did you restart the MySQL server so the changes would take? – Giacomo1968 Apr 09 '14 at 18:03