PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Internationalization » Translation2 » Bug #6270

Latin1 returned instead of UTF-8

Details

Submitted2005-12-16 20:48 UTC
Frompentarim at gmail dot com
Assignedquipo
StatusClosed
PackageTranslation2
PHP Version5.0.5
OSWindows XP
Roadmaps(Not assigned)

Comments

[2005-12-16 20:48 UTC] pentarim at gmail dot com

Description:
------------
I spotted a little bug in MDB storage driver.My MySql (5.0.15) stores all data in utf-8. I have hungarian language (in translation_i18n and translation_langs_avail tables), with utf-8 encoding. I used PEAR::MDB package for storage. The returned labels by Translation2 get function are latin1 encoded.

Reffering to:
http://forums.mysql.com/read.php?103,14397,25128
http://php.morva.net/manual/en/function.mysql-client-encoding.php

Partially resolved by adding to Translation2/Container/mdb.php at line 111 (after $this->db =& MDB::connect($db);):
$this->db->query("SET NAMES utf8");

It is hardcoded utf-8 this way, it would be better with encoding property in future like:
$this->db->query("SET NAMES ".$this->encoding);

Test script:
---------------
bundled example script

Expected result:
----------------
utf8 encoded characters

Actual result:
--------------
latin1 encoded characters

[2006-06-23 14:19 UTC] mstamat at csd dot uoc dot gr

If your database server holds one database only or if you want the same behavior for all your databases, you cound add to my.conf under the [mysqld] section the following line:
init_connect="SET NAMES utf8"

(picked up from http://golgote.freeflux.net/blog/archiv/php-mysql-4-1-and-utf.html)

Unfortunatelly, my server holds several databases that will break with the above fix, so I am looking forward for a solution within PEAR.
Currently I have done a similar hack with pentarim in the _connect() function of DB_DataObject. Admittedly, fixing MDB to support this sounds like a more appropriate solution.

[2006-06-23 15:11 UTC] pentarim at gmail dot com

I have tried it, I have lines in my.cnf like:

default-character-set=utf8
init-connect="SET NAMES utf8"

But on sql: SHOW VARIABLES LIKE "%character%" i get this

+--------------------------+----------------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files\xampp\mysql\share\charsets/ |
+--------------------------+----------------------------------------------+

It only helps when I run it "by hand", from connect function. This is a stupid mysql bug altrough, but it would be great if the driver could handle encodings. I tought that it is a stupid Win issue, but got exactly the same on debian. I have checked data, tables, collations, db , all are in UTF-8, so this is kind of black magic. I havent resolved this for half a year...