Zend_Auth_Adapter_DbTable UTF-8

发布于 2024-09-18 04:08:16 字数 1238 浏览 9 评论 0原文

以下是我从数据库获取身份的方法:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热鲨 2024-09-25 04:08:16

您可以在 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文