$book
is a 7kb string. If this query is executed using PHP PDO exec
, the monograph
column (LONGTEXT) data gets truncated at 6765 chara
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
It turned out to be that it is encoding issue. The are two solutions. The most obvious is to fix the encoding to match the database/connection settings. In my case, I was getting a iso-8859-1
string and interpreting it as a unicode.
However, it shouldn't be an issue anyway. I went further to discover that PDO::ATTR_EMULATE_PREPARES
is set to TRUE by default.