来自数据库的 cakephp 编码

标签 cakephp encoding

我在对数据库中的字符进行编码时遇到问题。我正在使用带有 win1250 编码的 Postgres,但是无论我在 core.php 中放入什么(现在我有这行代码):

Configure::write('App.encoding', 'iso-8859-1');

有时它会从数据库中给我一些奇怪的字母,例如 È 而不是 Č。有什么我可以做的来获得正确的编码。

注意 :我无法对数据库进行任何编辑或更改。

最佳答案

我认为您需要做的就是在数据库连接配置中声明正确的 encoding 选项,如 http://book.cakephp.org/2.0/en/development/configuration.html#database-configuration 中所述(稍微滚动一下)。

看看这个特别的段落:

encoding

Indicates the character set to use when sending SQL statements to the server. This defaults to the database’s default encoding for all databases other than DB2. If you wish to use UTF-8 encoding with mysql/mysqli connections you must use ‘utf8’ without the hyphen.



我在以前的项目中遇到了同样的问题(法语和西类牙语名称),我只需要在 $default 配置文件中的 app/Config/database.php 连接中添加以下内容:
'encoding' => 'utf8'

也许您需要 utf8 连接或您提到的 iso-8859-1

关于来自数据库的 cakephp 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13541096/

相关文章:

unicode - python编码转换

encoding - 有没有办法突出显示 Sublime Text 或任何其他文本编辑器中的所有特殊重音字符?

python - 分类特征编码作为 Scikit-Learn 的枚举

php - CakePHP 对派生字段中的条件进行分页

mysql - 在 Redis 中存储具有地理数据的对象列表的最佳方式

forms - 如何提交禁用表单字段的值?

java字符集解码问题

php - CakePHP - 多个 hasAndBelongsToMany 关系不起作用

windows - CakePHP:警告 (512):模型 "User"与模型 "User"无关 Windows 到 Ubuntu 部署

html - '字体系列 : Symbol' and Windows-1252