2016-11-21 92 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',