PHP, MySQL, Unicode, Set names
Posted by: Eric Zhang
Date: August 11, 2005 04:59PM

I am trying to store unicode characters in Mysql using PHP. However, I found interesting however weird things:

I use Chinese character as sample unicode content.


My php page's header is always "UTF-8".

Secenario 1:
I created my table using utf8 as character set.
I enter some chinese character on my php page, and insert the data to the table.
No matter whether I have "mysql_query("set names 'utf8'",$connection);" in my php code, the chinese character get stored
in the database perfectly. Since if I didn't set names, the default connection character set is "latin_1", so how can the chinese character be perfectly encoded and stored.

Secenario 2:
I created my table using latin_1 as character set.
I enter some chinese character on my php page, and insert the data to the table.
As long as I don't do "mysql_query("set names 'utf8'",$connection);" in my php code, the chinese character get stored
in the database perfectly.

So now I am little bit confused:
- Whether I really need to create a table using "utf-8" character set to store unicode content, like chinese characters.
- Even if I had such a table, do I need to do "set names", since my experience told me that it works even I didn't set it.

Options: ReplyQuote


Subject
Views
Written By
Posted
PHP, MySQL, Unicode, Set names
11581
August 11, 2005 04:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.