tags:

views:

93

answers:

1

I have a table like this, where one column is latin1, the other is UTF-8:

Create Table: CREATE TABLE `names` (
  `name_english` varchar(255) character NOT NULL,
  `name_chinese` varchar(255) character set utf8 default NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1

When I do an insert, I have to type _utf8 before values being inserted into UTF-8 columns:

insert into names (name_english = "hooey", name_chinese = _utf8 "鬼佬");

However, since MySQL should know that name_chinese is a UTF-8 column, it should be able to know to use _utf8 automatically.

Is there any way to tell MySQL to use _utf8 automatically, so when I'm programatically making prepared statements, I don't have to worry about including it with the right parameters?

+1  A: 

why not to use UTF-8 for the whole table?

Col. Shrapnel
That doesn't change the fact that I still have to specify `_utf8` for every column I insert into.
Neil
No, it does. just issue one query "SET NAMES charset" with every connect. where charset is your site charset @Neil.
Col. Shrapnel
Ah you're right. We can't actually change everything to UTF-8 here just yet, but I wrote a script to automatically put _utf8 in the inserts for the columns that are UTF-8 encoded.
Neil