MYSQL: Storing Foreign Characters ( chinese, arabic, etc )

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mattkenefick
Forum Newbie
Posts: 12
Joined: Tue May 29, 2007 1:01 pm

MYSQL: Storing Foreign Characters ( chinese, arabic, etc )

Post by mattkenefick »

I have a table setup in MySQL to contain different copy versions of this page. It's collation is "utf8_general_ci" and the type is "text". Will this be able to store Chinese Simplified/Traditional, Arabic, etc characters?

Not necessarily for english view, but for their viewing. So if I was in China, wrote on the Chinese keyboard and stored it.. Then refreshed my screen, I'd be able to see it or would the Collation mess it all up?

Thanks a ton!
And this is very very urgent. Sorry :(
francisjeffy
Forum Newbie
Posts: 17
Joined: Fri Feb 29, 2008 12:10 pm

Re: MYSQL: Storing Foreign Characters ( chinese, arabic, etc )

Post by francisjeffy »

Hi,

It will be stored in Unicode. Unicode is a set of numbers. For example every character in Chinese language will be represented using a unique number. So the text you enter in Chinese will be stored in MySql as a series of these Unicode representation of the text.

Hope that helps,

JeF.
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Re: MYSQL: Storing Foreign Characters ( chinese, arabic, etc )

Post by batfastad »

To make sure your PHP/MySQL solution is fully working with UTF-8 and Unicode, follow this excellent tutorial to make sure that everything is set up as it should be

http://www.nicknettleton.com/zine/php/p ... cheatsheet

But one extra thing that isn't mentioned in that text (but is buried down in the comments) is that you should also add a line immediately after you connect to MySQL.

So this:

Code: Select all

// CONNECT TO SQL
mysql_connect($sql_server, $sql_user, $sql_pass);
@mysql_select_db($sql_db) or die('Unable to select database');
Becomes this:

Code: Select all

// CONNECT TO SQL
mysql_connect($sql_server, $sql_user, $sql_pass);
@mysql_select_db($sql_db) or die('Unable to select database');
mysql_query("SET NAMES 'utf8'");
So just add that 4th line every time you connect to MySQL.

Hope this helps, B
Post Reply