【发布时间】:2013-07-05 21:19:31
【问题描述】:
我们正在使用 Laravel 4 针对旧数据库开发一个新站点。
数据库是只读的,我们无法转换它。
我们有
'charset' => 'cp1251'
在连接中,但是当我们尝试通过 Blade 输出一个字符串时,我们得到 p>
htmlentities(): Invalid multibyte sequence in argument
深入挖掘我们发现:
{{{ $shopProduct->product->sname }}}
编译为:
<h2><?php echo e($shopProduct->product->sname); ?></h2>
在哪里
function e($value)
{
return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
}
有没有办法让 Eloquent 或 PDO 从 MySQL 获取非 UTF-8 编码 (cp1251) 并实际在模型中使用 UTF-8?
注意:我们无法更改服务器上的数据库编码 - 这超出了我们的控制范围。
【问题讨论】:
-
只要
'charset' => 'utf8' -
成功了!哇,回想起来这是“常识”;)你能把它变成一个答案,所以我可以选择它吗? :) 谢谢!
-
app/config/database.php 中的数据库编码?
-
是的,这就是解决方案 - 将
app/config/database.php中的'charset' => 'cp1251'更改为'charset' => 'utf8'
标签: mysql character-encoding pdo laravel laravel-4