MySQL/PDO truncates the data

前端 未结 2 2020
心在旅途
心在旅途 2021-01-18 16:39

$book is a 7kb string. If this query is executed using PHP PDO exec, the monograph column (LONGTEXT) data gets truncated at 6765 chara

2条回答
  •  独厮守ぢ
    2021-01-18 17:16

    There are two points to be made here. One is that ideally all character encodings must be UTF8 - that's server, client, connection, and table. Two is that PHP's strlen function counts bytes, not characters.

    Your table character set may not be set to UTF8. You can do

    SHOW CREATE TABLE chemicals;
    

    to check that. You should also add these to your my.cnf:

    [mysqld]
    character-set-client=utf8
    character-set-results=utf8
    

    Read more about MySQL character sets here:

    MySQL character sets

提交回复
热议问题