When thinkphp executes 'setnamesutf8mb4', an error is returned.

Source: Internet
Author: User
Running environment: sae + thinkphpDB_CHARSET is utf8; (setting utf8mb4 directly causes an error. I don't know why ...) To support emoji expressions, the test code is as follows: publicfunctiontest () {code...} error prompt: [SQL statement]: setnamesutf8mb... running environment: sae + thinkphp
DB_CHARSET is utf8; (if you set it to utf8mb4 directly, an error is returned. I don't know why ...)
To support emoji expressions, the test code is as follows:
Public function test (){

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

Error message: [SQL statement]: set names utf8mb4.
Thank you for your guidance!

Reply content:

Running environment: sae + thinkphp
DB_CHARSET is utf8; (if you set it to utf8mb4 directly, an error is returned. I don't know why ...)
To support emoji expressions, the test code is as follows:
Public function test (){

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

Error message: [SQL statement]: set names utf8mb4.
Thank you for your guidance!

Select version (); check the database version. utf8mb4 is supported only in versions later than 5.5.

Mysql: utf8mb4

1. check the mysql version;
For versions later than mysql 5.5.3, the utf8mb4 character set is added. for previous versions, you must upgrade mysql server.
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 character set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.