問(wèn)題描述
我正在使用 Eloquent 將一個(gè)新人保存()到我的數(shù)據(jù)庫(kù)中.人名包含一個(gè)特殊字符 é 并且它不是提交.這是我的步驟和結(jié)果.
I'm using Eloquent to save() a new person into my database. 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
這給了我這個(gè)
當(dāng)我開(kāi)始使用 eloquent 時(shí),會(huì)發(fā)生以下情況.
When i start using eloquent the following happens.
$person = new Person();
echo $person->firstname = Input::get('firstname');
結(jié)果如下
知道可能出了什么問(wèn)題嗎?這些是我在 laravel 中的配置設(shè)置
Any idea what might be going wrong? These are my config settings in laravel
這是我在 phpmyadmin 中的數(shù)據(jù)庫(kù)
And this is my database in phpmyadmin
謝謝
推薦答案
我認(rèn)為它與數(shù)據(jù)庫(kù)沒(méi)有任何共同之處.
I don't think it has anything common with database.
使用時(shí):
$person = new Person();
echo $person->firstname = Input::get('firstname');
你在這里不使用數(shù)據(jù)庫(kù).您只需將屬性分配給 Person 類(可能使用 Eloquent),但您沒(méi)有將任何內(nèi)容放入數(shù)據(jù)庫(kù)并從數(shù)據(jù)庫(kù)中獲取任何內(nèi)容,因此編碼問(wèn)題不可能與數(shù)據(jù)庫(kù)本身有任何共同之處
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
我認(rèn)為潛在的問(wèn)題 - 您已經(jīng)在 Person
類中為 firstname
屬性定義了mutator,因?yàn)樗切懙?當(dāng)你從 Input 中得到它時(shí),它是大寫的) 所以你可能使用了一些像 strtolower
這樣的函數(shù),你應(yīng)該使用 mb_strtolower
來(lái)轉(zhuǎn)換 UTF-8 字符串而不會(huì)有問(wèn)題.
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.
這篇關(guān)于Laravel UTF-8 轉(zhuǎn)數(shù)據(jù)庫(kù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!