简体   繁体   English

Yii 2 不从 mysql 数据库渲染表情符号

[英]Yii 2 not rendering emojis from mysql database

I have a Yii 2 app and emojis are not rendering when I grab data from the database.我有一个 Yii 2 应用程序,当我从数据库中获取数据时,表情符号没有呈现。 It is storing inside my database fine as an emoji, but not in my view.它作为表情符号很好地存储在我的数据库中,但在我看来不是。 It's returning as a ?它作为 ? character.特点。

In my head I have在我的脑海里我有

<meta charset="utf-8">

Am I missing something?我错过了什么吗?

SOLUTION解决方案

Go into your db config file (where you set up your db name and password) and change charset to utf8mb4进入您的数据库配置文件(您在其中设置数据库名称和密码)并将字符集更改为 utf8mb4

Change the collation of the connection to utf8mb4 in your config file under the database component configuration like below在数据库组件配置下的配置文件中将连接的排序规则更改为utf8mb4 ,如下所示

'db'=>[
    'class' => 'yii\db\Connection' ,
    'dsn' => 'mysql:host=127.0.0.1;dbname=db_name' ,
    'username' => 'username' ,
    'password' => 'password' ,
    'charset'=>'utf8mb4'
]

or change the table collation configuration in the database或更改数据库中的表整理配置

ALTER TABLE Tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM