Home  >  Article  >  Backend Development  >  thinkphp reports an error when executing 'set names utf8mb4'

thinkphp reports an error when executing 'set names utf8mb4'

WBOY
WBOYOriginal
2016-10-11 14:23:192830browse

Running environment: sae + thinkphp
DB_CHARSET is utf8; (setting it directly to utf8mb4 will report an error, I don’t know why...)
If you want to support emoji expressions, the test code is as follows
public function test(){

<code>    $model = M('');
    $model -> query('set names utf8mb4');
}</code>

Error message: [SQL statement]: set names utf8mb4.
Please give me some guidance, thank you!

Reply content:

Running environment: sae + thinkphp
DB_CHARSET is utf8; (setting it directly to utf8mb4 will report an error, I don’t know why...)
If you want to support emoji expressions, the test code is as follows
public function test(){

<code>    $model = M('');
    $model -> query('set names utf8mb4');
}</code>

Error message: [SQL statement]: set names utf8mb4.
Please give me some guidance, thank you!

<code>select version();  看下数据库版本,5.5以上才支持utf8mb4
</code>

Mysql::utf8mb4

1. Check the version of mysql;
Mysql 5.5.3 and later versions add the utf8mb4 character set; previous versions need to upgrade the mysql server first.
2. MySQL utf8mb4 character set
Modify /etc/my.cnf

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

Restart MySQL Server and check the character set

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