If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Strange encoding problem (ISO-8859-2 and UTF-8)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-07, 18:03
pajakleon pajakleon is offline
Registered User
 
Join Date: Aug 2007
Posts: 2
Strange encoding problem (ISO-8859-2 and UTF-8)

Hello.

I have strange problem with encoding in my database, which has been already on three different mysql servers with various encodings.

At the beginning database was ISO-8859-2 (latin2). After migrations to new server
The columns are in UTF-8 (columns are: charset utf8, collate utf_general_ci).
But to display correctly national chars on site (utf-8 in php) i need to execute following commands in php after creating connection to database:
mysql_query("SET CHARACTER SET 'latin2'", $db);
mysql_query("SET NAMES 'latin2'", $db);

When i execute those commands, national string are correctly displayed on site. I've lived with this for one year, but now i need to connect to database in Java and there those commands don't work. I need to repair it.

Questions:
1. What is the encoding of text in my database UTF-8 or latin2(ISO-8859-2) ?
2. How to repair my database to have normal UTF-8 data without any tricls with setting CHARACETER SET and NAMES to latin2?
Reply With Quote
  #2 (permalink)  
Old 08-30-07, 09:32
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Why don't you just change the Character set for your tables?

Code:
ALTER TABLE <tablename> CHARACTER SET latin2 COLLATE latin2_general_ci;
Obviously you're going to get strange output (i.e. in UTF-8 format) unless you change the charset you're using.

My question to you is, why do you want it in UTF-8 if you're outputting in a different character set? Why don't you just use your original charset and collation? Is there any reasoning behind storing it as UTF-8 ?

Incidently you can use a select statement to set the output collation.
example :
Code:
SELECT _utf8'string' COLLATE utf8_general_ci FROM <tablename>;
Also, the statements you provide above:
Quote:
mysql_query("SET CHARACTER SET 'latin2'", $db);
mysql_query("SET NAMES 'latin2'", $db);
Are valid SQL for MySQL.
So i imagine there is no harm in doing an SQL query in Java that is "SET CHARACTER SET 'latin2'" and "SET NAMES 'latin2'" ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On