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

后端 未结 4 1567
灰色年华
灰色年华 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:39

    In your PDO connecton, set the charset.

    new PDO('mysql:host=localhost;dbname=the_db;charset=utf8mb4', $user, $password);
    

提交回复
热议问题