displaying Korean characters from mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gth759k
Forum Commoner
Posts: 76
Joined: Mon Jun 15, 2009 3:04 am

displaying Korean characters from mysql database

Post 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 :

???? ??
???? ??
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: displaying Korean characters from mysql database

Post 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.
gth759k
Forum Commoner
Posts: 76
Joined: Mon Jun 15, 2009 3:04 am

Re: displaying Korean characters from mysql database

Post 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.
Post Reply