Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert korean characters to mysql

Tags:

sql

php

mysql

I want to insert some phrases to MySQL

the first field is english and the second one is korean. the problem each time I insert the value from my PHP script it's shows in the MYSQL like this. 학교

However, if I insert the the same korean value from PhpMyAdmin it will works, so the problem from the php script. I've found in the web that I have to change the Collation in MySQL?

Any help ?

<?

//*---------------------------------------------------------*\\
//* if POST
//*---------------------------------------------------------*\\
if($_POST['addphrase'])
{
    $SQL = "INSERT INTO `sd_phrases` VALUES(NULL,?,?)";
    $db = new db();
    $db->execute($SQL,$_POST['english'],$_POST['korean']);
    $box = new true_box();
    $box->init('PLease Wait....','index.php?action=phrases');
    die();
}

?>
<form method="post">
<center>
    <table class="horz">
    <tr><th colspan="2">Add a new Phrase</th></tr>
    <tr><td>English Phrase</td><td><div align="left"><input type="text" size="80" name="english"></div>
    </td></tr>
    <tr><td>Korean Phrase</td><td><div align="left"><input type="text" size="80" name="korean"></div>
    </td></tr>
    <tr><td colspan="2"><input type="submit" value="Add" name="addphrase"></td></tr>
    </table>
</center>
</form>

enter image description here

enter image description here

like image 598
Othman Avatar asked Dec 26 '22 22:12

Othman


2 Answers

The collation should be set to utf8_unicode_ci as Danack57 says.

You should use just UTF8 as your character encoding scheme.

default-character-set = utf8

After opening each mysql connection, execute set names utf8; Read this

like image 179
Anirudh Ramanathan Avatar answered Jan 11 '23 23:01

Anirudh Ramanathan


The problem is the way the html page is reporting the encoding to the users browser. I suspect one is reporting as utf8 and the other is reporting as some other encoding. So when the values got posted back from the browser, the are encoded differently. Php does not do the encoding, it more or less takes what the forms post to it. Load with pages and check the encoding in the web browseraan see if you can get the two page to report the same encoding using meta tags.

like image 23
iWantSimpleLife Avatar answered Jan 11 '23 23:01

iWantSimpleLife