DataObject, mysql 4.1, unicode

From: Date: Tue, 18 Jan 2005 12:05:59 +0000
Subject: DataObject, mysql 4.1, unicode
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16992@lists.php.net to get a copy of this message
Hi all, I am using php5.0.3 and mysql 4.1, and the latest DataObjects package. The entire db is unicode general and I am using the mysqli driver. If i do not expliclity call a "set name 'utf8' " query before a find(), all i get back is a bunch of question marks.... By example: $DO_trans = DB_DataObject::factory('translations'); $DO_trans->query("SELECT * FROM {$DO_trans->__table} ORDER BY fk_localeid, section"); I get a bunch of ???? marks for various value fields. ( remember all collations are unicode_general). IF i do this: $DO_trans = DB_DataObject::factory('translations');
$DO_trans->query("SET NAMES 'utf8'");            <-----added this line
$DO_trans->query("SELECT * FROM {$DO_trans->__table} ORDER BY fk_localeid, section"); Then all my results are indeed as expected, with all characters including, chinese, and japanese characters coming back as they should. THERE has got to be a better way! I am using DataObjects on a year long project. I will end up writing $DO_[some name here]->query("SET NAMES 'utf8'"); a million times before its over! Not too mention running 2 querries for everyone 1 that i needed. Do you know if: 1- I can simply add an option to the dsn like:
mysqli://user:password@localhost/database?character_set_connection=utf8    ?   (this doesnt work btw)
2- Can I hack the DataObject file to always call a SET NAMES 'utf8' query before running the "find()" method?  ( a ton of extra querries for something that should be automated, least favorite idea )
3- Some magical setting for mysqli somewhere?  In an ini file for the mysql or php?
in a jam, and thanks for your time, John

« previous php.pear.general (#16992) next »