워드프레스 UTF8 문제해결
- Wordpress 2.0.4 기준 -
워드프레스를 국내 웹호스팅에서 사용하려다 보면 가끔 모든 설정이 정상(?)으로 되어있음에도 한글이 깨지는 경우를 볼 수 있다.
이는, 제로보드(zb5말고, 이전버전)때문에 생긴 기형적인 현상으로, MySQL은 UTF-8로 되어있지만, Apache서버가 EUC-KR로 되어있는 바람에 인코딩 문제가 발생하게 된다.
가장 좋은 해결책은 Apache 서버를 UTF-8로 인코딩을 바꾸는 것이겠지만, 국내 웹 호스팅업체에서는 그렇게 했다가는 기존 다른 계정 사용자들의 제로보드가 꼬이는 현상을 일으키게 된다.
따라서, 대개 호스팅업체에서 이 문제를 해결해 주지는 않는다.
이럴 경우, /wp-includes/wp-db.php 를 열어 42번째 줄을 찾아보면, wpdb()함수가 있다. 이를 다음처럼 고치면 된다. (정확하게는 mysql_query("SET NAMES UTF8"); 한줄을 추가하는 것으로 된다.)
[php]function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$this->dbh) {
$this->bail(”
Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at $dbhost. This could mean your host’s database server is down.
- Are you sure you have the correct username and password?
- Are you sure that you have typed the correct hostname?
- Are you sure that the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.
“);
}
mysql_query(”SET NAMES UTF8″);
$this->select($dbname);
}[/php]