0

I am storing non-English characters in a MySQL data base for example: الجزائر

Unfortunately these characters get stored in my database and get displayed as questions marks like this:

??????

I am using CodeIgniter active record as my Database abstraction layer and I have my database collation set as utf8_unicode_ci.

How can I store the characters properly using MySQL?

Jethro Hazelhurst
  • 3,230
  • 7
  • 38
  • 80
  • 1
    Did you check your table collation only? You need to check collation of the fields also. – Koray Küpe May 09 '17 at 10:37
  • You should have store it at collation set as utf8_general_ci or utf8mb4_general_ci for both table and field. – Web Artisan May 09 '17 at 10:38
  • In fact I only changed the field collation... not the table collation... hmmm. – Jethro Hazelhurst May 09 '17 at 10:38
  • I did not know about the table collation.... so I have to set both the table and the field collation to utf8_general_ci? – Jethro Hazelhurst May 09 '17 at 10:39
  • 1
    Yes. then try gain – Web Artisan May 09 '17 at 10:39
  • Try to set collation utf8mb4_general_ci – Dileep kurahe May 09 '17 at 10:40
  • Nope, not working. – Jethro Hazelhurst May 09 '17 at 10:41
  • It's just refusing to work... I set both the table and the field to utf8mb4_general_ci. Very frustrating. – Jethro Hazelhurst May 09 '17 at 10:44
  • This problem is usually due to a setting in MySQL that does not match the settings for the application program or the operating system. Here are some common steps for correcting these types of issues: This is copy of beginning explanation here https://dev.mysql.com/doc/refman/5.7/en/faqs-cjk.html#faq-cjk-why-cjk-question-marks – b2ok May 09 '17 at 10:45
  • Hmm... tried adding default_charset = "UTF-8" & mbstring.internal_encoding = UTF-8 to my php ini, tried adding `'dbcollat' => 'utf8mb4_general_ci'` to by database config file... tried changing my MySQL collation and nothing seems to be working. – Jethro Hazelhurst May 09 '17 at 11:00
  • @JethroHazelhurst - See "question mark" in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored for likely causes and cures. – Rick James May 09 '17 at 16:18
  • @KorayKüpe - Only the "encoding" (`CHARACTER SET`) is a problem; sort order (`COLLATION`) is irrelevant for this Question. – Rick James May 09 '17 at 16:20
  • The _database_ settings (charset & collation) are only _defaults_ for tables. The _table_ settings are only _defaults_ for columns. You must look at `SHOW CREATE TABLE` to see what you really have. – Rick James May 09 '17 at 16:21
  • @JethroHazelhurst - How are you "storing" those characters? Via Java? HTML form? PHP? phpmyadmin? Something else? The problem is likely to be there. – Rick James May 09 '17 at 16:24
  • @Rick James, thanks for the comments... I am storing the data via an HTML form. The form data is handled by codeigniter and I used phpmyadmin to set up my database. – Jethro Hazelhurst May 09 '17 at 16:44
  • Look for the "character encoding" when running the form. Look at "view source"; is there a `meta` tag at the top, are any attributes on the `form` tag? – Rick James May 09 '17 at 17:03
  • My HTML template has on the top... the form tag only has an id, action and a method attribute. – Jethro Hazelhurst May 09 '17 at 17:05

0 Answers0