Client-side and Server-side encoding

Récupérer les accents français quand MySql parle latin… au lieu de UTF-8

Apache Server 2.0.54
PHP 5.0.4
MySQL 4.1.12
and WordPress 1.5.1.3

The problem all originates from MySQL 4.1

version 4.1 MySQL supports different language encodings

problem : “Client” encoding language and the “Server” encoding language.

The “Client” was set to Latin-1 encoding
The “Server” was set to UTF-8

“MySQL tries to translate from one language to the other when it puts the information in its Database. The problem is, my WordPress encoding already was UTF-8. So MySQL basically took UTF-8 encoded text (from WordPress) and treated it as Latin-1 encoded text and tried to convert it to UTF-8. Doing that, some characters where fine but more complex ones where not…

To solve this problem, you have to tell MySQL to treat all the stuff from WordPress as UTF-8 stuff.

First open the file: wordpress\wp-includes\wp-db.php

Find line 56, it should read as this:
$this->select($dbname);

Go to the beginning of the line and punch “enter” to make it move one line down and leave a blank line on line 56.

Then place this line at line 56:
$this->query(“SET NAMES ‘utf8′”);

Then your lines should look like this:
56 $this->query(“SET NAMES ‘utf8′”);
57 $this->select($dbname);

“now have a wordpress that can display and retain text in any language your computer can write in :)”

One final note, your Database must be a UTF-8 Database and your WordPress encoding must be UTF-8 also. For wordpress, you can find this in Options/Reading.

Japanese Characters not displaying right!

The patch we found that seems to have worked for some people but not for others was to add the line $this->query (“SET NAMES ‘utf8′”); after line 43 in wp-db.php.
http://wordpress.org/support/topic/48459?replies=6

PHP, MySQL 4.1 and UTF-8

Advertisements

~ by netlex on October 15, 2006.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: