我使用Zend_Db的,並試圖改變字符集爲utf8,這裏是代碼:最好的方式來設置字符集爲Zend_Db的(或者好至少比我目前做的)
config.ini文件:
[development]
db.host = "localhost"
db.username = "root"
db.password = "toor"
db.dbname = "db_whoopdiedo"
db.charset = "utf8"
bootstrap.php中:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initAutoload()
{
Zend_Registry::set(
'config',
new Zend_Config_Ini(APPLICATION_PATH.'/configs/config.ini', 'development')
);
Zend_Registry::set(
'db',
Zend_Db::factory('Pdo_Mysql', Zend_Registry::get('config')->db)
);
Zend_Registry::get('db')->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Registry::get('db')->query("SET NAMES 'utf8'");
Zend_Registry::get('db')->query("SET CHARACTER SET 'utf8'");
}
}
我認爲這將是足夠的添加字符集的配置,但他只applys它,如果我把它直接使用:
Zend_Registry::get('db')->query("SET NAMES 'utf8'");
Zend_Registry::get('db')->query("SET CHARACTER SET 'utf8'");
我的問題:有沒有更好的方法來設置字符集,也許配置明智?
多數民衆贊成我稱之爲徹底:D工程就像一個魅力,謝謝你! – Hannes 2010-11-16 10:14:26