简体   繁体   中英

Zend_Auth_Adapter_DbTable UTF-8

Here is how I am getting an identity from a database:

$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);

The problem with this is that the getResultRowObject() returns an object with messed up diacritics. My database has UTF-8 encoding as well as all my tables.

So instead of:

Košice

I get:

Košice

This is how I am creating the db adapter:

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();
}

You can add in your config.ini a charset param, so no need to execute SET NAMES on your own. I have something like this in all my ini's and works fine:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM