Inserting UTF-8 encoded string into UTF-8 encoded mysql table fails with “Incorrect string value”

后端 未结 4 1560
灰色年华
灰色年华 2020-12-01 15:17

Inserting UTF-8 encoded string into UTF-8 encoded table gives incorrect string value.

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect str

4条回答
  •  被撕碎了的回忆
    2020-12-01 15:36

    I fixed the error: SQLSTATE[HY000]: General error: 1366 Incorrect string value ...... with this method:

    I use utf8mb4_unicode_ci for database Set utf8mb4_unicode_ci for all tables

    Set longblog datatype for column (not text, longtext.... you need big datatype to store 4 bytes of your content)

    It is okay now. If you use laravel, continue to edit config/database.php

    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    

    If you use function strtolower, replace it with mb_strtolower Notice: you have to put on your head tag

提交回复
热议问题