Joel
Joel

Reputation: 6107

Latin1_swedish_ci Encoding in MySQL

I am using UTF-8 encoding on my website. Lately I have been storing chinese/spanish/russian names in my MySQL tables and then printing them with PHP on a page generated with a charset of UTF-8. The page works fine and I see all the letters correctly. However, I just realized that my table is set with latin1_swedish_ci charset. How is it possible that even though I stored these names with latin1_swedish_ci charset, serving them on my site with UTF-8 still shows them up correctly?

Thanks!

Joel

Upvotes: 1

Views: 8044

Answers (2)

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

You would be interested in thread: A script to change all tables and fields to the utf-8-bin collation in MYSQL

They are dealing there with ways of repairing same things you have done.

Note that when used in primary keys, size of varchar encoded in utf8 count triple, so the maximal length for single primary key column is varchar(333).

Upvotes: 1

ajreal
ajreal

Reputation: 47311

Because mysql connection is still using latin1,
you should treat these data is in UTF-8 but store in latin1 environment.

So, to prove it,

show variables like '%char%';

the above should return most of the setting is in latin1

apply

set names utf8;

And you would see all the UTF-8 become double encoded (garbled)

Upvotes: 2

Related Questions