thinkphp Execute ' Set names UTF8MB4 ' Error

Source: Internet
Author: User
Operating Environment: SAE + thinkphp
Db_charset is UTF8; (directly set to UTF8MB4 will be an error, I do not know why ...) )
To support the emoji expression, the test code is as follows
Public Function test () {

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

Error message: [SQL statement]: set names UTF8MB4.
Ask the great God for some guidance, thank you!

Reply content:

Operating Environment: SAE + thinkphp
Db_charset is UTF8; (directly set to UTF8MB4 will be an error, I do not know why ...) )
To support the emoji expression, the test code is as follows
Public Function test () {

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

Error message: [SQL statement]: set names UTF8MB4.
Ask the great God for some guidance, thank you!

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

Mysql::utf8mb4

1, check the version of MySQL;
After MySQL 5.5.3 version, add utf8mb4 character set; the previous version should upgrade 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, check the 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.