[英]Laravel UTF-8 To Database
I'm using Eloquent to save() a new person into my database. 我正在使用Eloquent将一个新人保存到我的数据库中。 The persons name contains a special character é and it's not submitting. 人名包含特殊字符é ,但不提交。 Here are my steps and the results. 这是我的步骤和结果。
echo Input::get('firstname'); // Miguél
Which gives me this 这给了我这个
When i start using eloquent the following happens. 当我开始使用雄辩时,会发生以下情况。
$person = new Person();
echo $person->firstname = Input::get('firstname');
This produces the following result 这产生以下结果
Any idea what might be going wrong? 知道可能出了什么问题吗? These are my config settings in laravel 这些是laravel中的配置设置
And this is my database in phpmyadmin 这是我在phpmyadmin中的数据库
Thanks 谢谢
I don't think it has anything common with database. 我不认为它与数据库有任何共同之处。
When you use: 当你使用:
$person = new Person();
echo $person->firstname = Input::get('firstname');
you don't use database in here. 你不在这里使用数据库。 You just assign properties to Person class (that probably uses Eloquent) but you don't put anything into database and get anything from database so it's not possible that the encoding problem has anything in common with database itself 您只需将属性分配给Person类(可能使用Eloquent),但您不会将任何内容放入数据库并从数据库中获取任何内容,因此编码问题不可能与数据库本身有任何共同之处
Potential problem in my opinion - you have defined mutator in Person
class for firstname
attribute because you have it in lowercase (when you get it from Input it's with capital letter) so you probably use some function like strtolower
and you should use mb_strtolower
to convert UTF-8 strings without a problem. 在我看来可能存在的问题 - 你已经在Person
类中为firstname
属性定义了mutator,因为你用小写字母(当你从输入它得到大写字母时),所以你可能使用像strtolower
这样的函数你应该使用mb_strtolower
来转换UTF -8字符串没有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.