Page 1 of 1

displaying Korean characters from mysql database

Posted: Thu Jul 23, 2009 6:10 pm
by gth759k
So, this isn't really a php question, but I'm hoping someone can help me. I'm trying to make a script that changes the language to korean with a variable. I have a table set up called translations with a row that has both the english and korean translations of a particular phrase. When I created the table I made korean_translation of Collation euckr_korean_ci and after I save the information, phpmyadmin displays the characters the way they should be. However, when I run the script below, my browser displays $translation1 wrong, where as it displays $suposedtobe correctly. The script below must be saved with notepad as UTF-8, neither will be displayed correctly if you save it as ACSII. Can anyone help me out. Any help would be appreciated. Thanks.

Code: Select all

 
<?php
    require('config.php');
    $connection = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS) or die('Could not connect to MySQL database. ' . mysql_error());
    $db = mysql_select_db(SQL_DB,$connection);
    
    $sql = "SELECT translation_id, translation_name, english_translation, korean_translation FROM translations WHERE translation_name='translation1'";
    $result = mysql_query($sql) or die(mysql_error());
    $data = mysql_fetch_array($result, MYSQL_ASSOC);
    
    $language = 'korean';
     
    if ($language == 'english') {
        $translation1 = $data['english_translation'];
        echo $translation1;
        echo '<br>';
        $suposedtobe = 'Hello World';
        echo $suposedtobe;
    }
    else if ($language == 'korean') {
        $translation1 = $data['korean_translation'];
        echo $translation1;
        echo '<br>';
        $suposedtobe = '???? ??';
        echo $suposedtobe;
    }
?>
 
The script outputs :

???? ??
???? ??

Re: displaying Korean characters from mysql database

Posted: Sat Jul 25, 2009 8:43 am
by cpetercarter
It could be a browser problem. Before you echo the translations, have you already echoed a <head> section, containing something like :

Code: Select all

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
 
so that your browser knows what character-set to expect?

Alternatively, the problem may lie in the process of retrieving data from the database. Try adding :

Code: Select all

mysql_set_charset('utf8');
immediately after the line which establishes a database connection.

Re: displaying Korean characters from mysql database

Posted: Mon Jul 27, 2009 4:28 am
by gth759k
It wasn't a problem. All I had to do was create a php/mysql application where I put the translations into the database from my form instead of phpmyadmin and then they display on the page correctly. I didn't even have to change the char-set in my table. Thanks though.