代码之家  ›  专栏  ›  技术社区  ›  Richard Knop

Zend\u Auth\u适配器\u DbTable UTF-8

  •  1
  • Richard Knop  · 技术社区  · 14 年前

    $adapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('dbAdapter'));
    $adapter->setTableName('clients');
    $adapter->setIdentityColumn('email');
    $adapter->setCredentialColumn('password_hash');
    // etc
    
    $client = $adapter->getResultRowObject(null, array('password_hash'));
    Zend_Session::rememberMe(604800);
    // store client object in the session
    $authStorage = $auth->getStorage();
    $authStorage->write($client);
    

    所以不是:

    Košice
    

    Košice
    

    以下是我创建db适配器的方法:

    protected function _initDb()
    {
        $this->configuration = new Zend_Config_Ini(APPLICATION_PATH
                                                   . '/configs/application.ini',
                                                   APPLICATION_ENVIRONMENT);
        $this->dbAdapter = Zend_Db::factory($this->configuration->database);
        Zend_Db_Table_Abstract::setDefaultAdapter($this->dbAdapter);
        $stmt = new Zend_Db_Statement_Pdo($this->dbAdapter,
                                          "SET NAMES 'utf8'");
        $stmt->execute();
    }
    
    1 回复  |  直到 12 年前
        1
  •  1
  •   robertbasic    14 年前

    你可以加入你的配置.ini一 charset param,所以不需要执行 SET NAMES 靠你自己。我所有的ini里都有这样的东西,效果很好:

    resources.db.adapter = mysqli
    resources.db.params.host = localhost
    resources.db.params.username = user
    resources.db.params.password = pass
    resources.db.params.charset = utf8
    resources.db.params.dbname = db