1

I uploaded my website to the new server. It works perfectly on my test server at home, there is not a different setup the databases were copied over word for word. But on the site anything that is in Korean displays as ??????. The database stored it correctly and the pages all have <meta charset="UTF-8"> I can not figure out what I am missing.

EDIT: The text displays fine in the database when I use phpMyADMIN

chris3spice
  • 191
  • 2
  • 10
  • 2
    possible duplicate of [Arabic data transfer between multiple tables in different MySQL databases returning ???????? as new values](http://stackoverflow.com/questions/22968345/arabic-data-transfer-between-multiple-tables-in-different-mysql-databases-return) – Giacomo1968 Apr 20 '14 at 16:29
  • Also this answer from this question. http://stackoverflow.com/questions/20624445/characters-like-not-displaying-correctly-from-mysql/20624493#20624493 – Giacomo1968 Apr 20 '14 at 16:37

3 Answers3

0

The issue is most likely a different in database collation settings between your home test server & your new remote server. Meaning that while your database was transferred correctly, the way that data is then spit out of database is a whole other thing.

What is the data collation of the database giving you an issue? By default, most MySQL installs set latin1_swedish_ci instead of utf8_general_ci for newly created databases.

Change the collation of the database & try again.

ALTER DATABASE [name of your database] CHARACTER SET utf8;

If this is a specific table, the collation can be changed as so:

ALTER TABLE [name of your table] CONVERT TO CHARACTER SET utf8;

And if it is a specific column in a table:

ALTER TABLE [name of your table] MODIFY [name of your column] [other settings] CHARACTER SET utf8 COLLATE utf8_general_ci;

Or perhaps you could export the current database, create a new database with this command & reimport the data:

CREATE DATABASE [name of your database] CHARACTER SET utf8 COLLATE utf8_general_ci;

And if you want to make a permanent change to the MySQL install on the machine giving you an issue, go and edit my.cnf. The following would set the whole chain to UTF-8:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

EDIT: The original poster states that the connection & DB are all UTF8 clean. But what about trying an edit to the Apache default character set. Go here & open the character set file for Apache like so:

sudo nano /etc/apache2/conf.d/charset

And uncomment the line that looks like this:

#AddDefaultCharset UTF-8

So it looks like this:

AddDefaultCharset UTF-8

And restart Apache. This is not a great idea for a long term setup in my humble opinion, but if t solves the issue it indicates there is something in your codebase that can be changed to affect the same results without having to force Apache to force UTF8.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
  • unfortunately that did not solve the problem, I've checked each individual table and matched my settings exactly to the home test server but its still not working – chris3spice Apr 20 '14 at 16:43
  • Did you check the MySQL config in `my.cnf`? Did you then restart the MySQL server? Also, what is your scripting language? PHP? If PHP what is your connection interface? You could explicitly set the connection to UTF8 like so: `mysqli_query($dbcon, "SET NAMES 'utf8'");` – Giacomo1968 Apr 20 '14 at 16:44
  • Yes I did change the my.cnf and I restarted the entire server actually. Scripting is done in PHP and some pages are loaded in the background using JQuery. My interface is `$conn = new PDO('mysql:host=localhost;dbname=kumiho;charset=utf8', $username, $password);` – chris3spice Apr 20 '14 at 16:49
  • Nope still not working, went through apache settings, dropped the database and created it from scratch, with some hand entered test data still no go. On the odd side I took a super old database I had that converted korean weirdly... it will display the Korean if it looks like `ê³ ì–‘ì´` in the database – chris3spice Apr 20 '14 at 17:16
  • @chris3spice “it will display the Korean if it looks like ê³ ì–‘ì´ in the database” Here’s an idea: Maybe the remote server is fine, but your local test environment is the one that has the kludges to make this work? Think about it. – Giacomo1968 Apr 20 '14 at 17:20
  • 1
    Maybe, but I can not find a difference in my setup though, my local environment is a virtual server run just like the real server, down to the same OS. – chris3spice Apr 20 '14 at 17:45
0

In PDO (php api), you need set charset $conn->exec('SET CHARACTER SET utf8');.

PHP example:

<?php
//한국어/조선말

header('Content-Type: text/html; charset=utf8');

$username = 'user';
$password = 'password';
$host = 'domain';
$db = 'dbtest';

try {
    $conn = new PDO('mysql:host=' . $host . ';dbname=' . $db . ';charset=utf-8', $username, $password);
    $conn->exec('SET CHARACTER SET utf8');//This solve the problem
    $stmte = $conn->prepare('SELECT id, text FROM test LIMIT 10');
    $exec = $stmte->execute();

    if ($exec) {
        while($reg = $stmte->fetch(PDO::FETCH_OBJ)){
            echo 'id: ' . $reg->id . '<br />';
            echo 'text: ' . $reg->text . '<br /><hr />';
        }
    } else {
        echo 'Error SELECT';
    }
} catch(PDOException $e){
    echo 'PDOException: ', $e->getMessage();
}
?>

Mysql example:

CREATE DATABASE `dbtest` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

USE `dbtest`;

CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` varchar(300) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT INTO `test` (`id`, `text`) VALUES (1, '한국어/조선말');

Use phpmyadmin in your server to verify that the DATABASE on your server is "utf8", see: phpmyadmin 3.5

In your database must be something else.

if your database is correct (after checking with the utf8) then the problem is in some PHP file.

To resolve you should save all php files (both the major and the includes)

Save your html file (or php file) in "utf8 without boom", using notepad++, see:

save in utf8 without boom

Add in your PHP files (in top file):

<?php
header('Content-Type: text/html; charset=utf8');
?>

Files included should be saved in utf8-without-boom also, example:

<?php
include('YOUR FILE INCLUDED.php');// Save "YOUR FILE INCLUDED.php" in UTF8-without-boom
?>

Maybe its some page is in ANSI (for example "form.php").

Note: All PHP files must be in UTF8-without-boom format

Protomen
  • 9,471
  • 9
  • 57
  • 124
  • The original poster states, “It works perfectly on my test server at home.” which means the files themselves are saved correctly. – Giacomo1968 Apr 20 '14 at 16:39
  • No need for any negative vote, we're just trying to help you. Do not be so radical. [Edited] Very "online publishers" save the files without utf8 (saving in "latin1"). Can not know for sure what he did wrong. – Protomen Apr 20 '14 at 16:40
  • Thanks for the help, but yeah I don't think that's the issue – chris3spice Apr 20 '14 at 16:44
  • I always set the charset to UTF-8, its become habit because I'm always working in Japanese or Korean. I didn't negative vote you btw, I never negative vote anybody on this site – chris3spice Apr 20 '14 at 17:09
  • @chris3spice If your php-file is not in utf8 data will be saved in "latin1", you must save the files to include (`include('file_inc.php');`) in as utf8-without-boom, I edited my answer. Try phpmyadmin, maybe the table is in utf8, but the field is in latin1 – Protomen Apr 20 '14 at 17:19
  • Thanks, I will see if that makes a difference, I use brackets for all my coding so I'll have to download notepad++ – chris3spice Apr 20 '14 at 17:21
  • @JakeGould my answer did not miss anything he said, it only means that must be some flaw in time to upload the php files, include files (`include(...);`) affect the charset of the page. Your negative vote was unnecessary. If the database is OK, as he said, then the fault is logically in a PHP file. – Protomen Apr 20 '14 at 17:23
  • @GuilhermeNascimento Looking at your edit history it also looks like you are changing your answer to basically swipe my answer which focuses on the database. Which is my answer. So seriously, get a grip. – Giacomo1968 Apr 20 '14 at 17:28
  • @JakeGould I'm just trying to help, from the beginning I said the problem is more likely to be in "php" and you started with a reckless attitude (negative vote) not sure of the cause of the problem. And now comes with charges. Then I'll remove the part of the "CREATE TABLE" if you like (I had not read your reply). I'm just trying to help. Do not come with accusations and aggressive attitudes. – Protomen Apr 20 '14 at 17:36
  • I opened all my files in notepad++, when I went to check the encoding they already had UTF-8 without BOM marked as the encoding type. I also tried creating a test database on the remote server and it still shows the same problems. I think its not in the PHP or MySQL but some setting on the server... but I can not find a difference between my Local Testing Server and the Remote one – chris3spice Apr 20 '14 at 17:49
  • @chris3spice are you sure that the server files are also in utf8? – Protomen Apr 20 '14 at 17:50
  • Yes the standard encoding for all files on the server are UTF8 and checking some of the files myself they are encoded UTF8 – chris3spice Apr 20 '14 at 18:07
0

Try adding lang attribute to your html tag

<html lang="ko">
Vishnuraj V
  • 2,819
  • 3
  • 19
  • 23