Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.4

Bug #6270 Latin1 returned instead of UTF-8
Submitted: 2005-12-16 20:48 UTC
From: pentarim at gmail dot com Assigned: quipo
Status: Closed Package: Translation2
PHP Version: 5.0.5 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [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

Comments

 [2006-06-23 14:19 UTC] mstamat at csd dot uoc dot gr (Manolis Stamatogiannakis)
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...
 [2006-09-27 12:21 UTC] quipo (Lorenzo Alberton)
if you're using the MDB2 driver, just set the 'charset' option in the $dbinfo: =========================================== $dbinfo = array( 'hostspec' => 'host', 'database' => 'dbname', 'phptype' => 'mysql', 'username' => 'user', 'password' => 'pwd', 'charset' => 'utf8', ); $tr =& Translation2::factory('MDB2', $dbinfo, $params); =========================================== if you're using MDB or DB, then I'm afraid I can't help, both packages are deprecated and they don't accept new features.
 [2006-11-14 20:16 UTC] quipo (Lorenzo Alberton)
I've just committed a new setCharset() method into CVS. If you're using the MDB2 driver, this method will probably save you some headaches ;-) HTH