2016-11-21 95 views
0

我嘗試將數據從Firebase導入MySQL數據庫。使用Yii2將Firebase中的Android表情符號保存到MySQL

我的火力地堡的數據是這樣的:

enter image description here

現在,我試圖讓這個記錄並保存到MySQL:

$model = new DbModel(); 
$wpath = "/messages/". $id; 
$wvalue = $firebase->get($wpath); 

$wjson = json_decode($wvalue, true);    
$model->message = $wjson["message"]; //this is ok, if I print it'll show the emoji 
$model->save(); 

後,我保存模型,我得到這個我的數據庫:

I'm going to dance ???? 

我設置utf8mb4_general_ci我在列表中的列的排序規則,似乎工作當我通過腳本或UI手動插入相同的文本,但是當我通過php保存我的模型時,表情符號不保存。

我的服務器版本:10.1.16-MariaDB - mariadb.org binary distribution

Web服務器:Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9

任何建議將高度讚賞。

回答

2

終於找到了解決here 更改數據庫連接設置的字符集,以及重要的是:

'components' => [ 
    'db' => [ 
     'class' => 'yii\db\Connection', 
     'dsn' => 'mysql:host=localhost;dbname=db', 
     'username' => 'root', 
     'password' => '', 
     'charset' => 'utf8mb4',