thinkphp reports an error when executing 'set names utf8mb4'

WBOY
Release: 2016-10-11 14:23:19
Original
2839 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

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

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!