Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    2

    Unanswered: 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?

  2. #2
    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:
    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'" ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •