Home >PHP Framework >YII >Chinese garbled characters appear when the yii framework accesses the database

Chinese garbled characters appear when the yii framework accesses the database

王林
王林Original
2020-02-27 14:58:432133browse

Chinese garbled characters appear when the yii framework accesses the database

Problem:

The database encoding is utf8, and the Yii connection database encoding is also utf8, but the Chinese data retrieved is garbled.

Reason:

When entering the sql statement to insert Chinese data in the terminal, the environment is not utf8, so the data stored in the mysql database is not utf8 encoded, and the data taken out is garbled.

(Recommended tutorial: yii framework)

Solution:

When entering the sql statement to insert Chinese data in the terminal, you need to set the encoding first The environment is utf8, such as:

set names utf8

Just save the inserted data as utf8.

For more programming-related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of Chinese garbled characters appear when the yii framework accesses the database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn