MySQL/PDO truncates the data

前端 未结 2 2024
心在旅途
心在旅途 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:29

    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.

    • You will find this topic as a useful summary to understand what does the latter setting mean, PDO MySQL: Use PDO::ATTR_EMULATE_PREPARES or not?.
    • This topic will explain why the encoding messed up the query, The way PDO parametrized query works.

提交回复
热议问题