以下是我从数据库中获取身份的方法:
$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);
这个问题是getResultRowObject()返回一个带有混淆变音符号的对象。我的数据库有UTF-8编码以及我的所有表格。
所以而不是:
Košice
我明白了:
Košice
这就是我创建数据库适配器的方式:
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();
}
答案 0 :(得分:1)
您可以在config.ini中添加charset
参数,因此无需自行执行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