MySQL / PDO truncates data

$book- line 7kb. If this query is executed using PHP PDO exec, the column data monograph(LONGTEXT) is truncated with character 6765:

echo strlen($book); // output 7157

$db->exec("UPDATE `chemicals` SET `monograph` = {$db->quote($book)} WHERE `id` = {$db->quote($c['id'])};");

However, if I print a query and execute it using an SQL client (bypassing PHP), it inserts all the data into the database. This makes me think this is a PHP setting that I am not familiar with yet.

Please note that the same thing happens if I use prepared statements (including with PDO :: PARAM_LOB).

$bookthe value is reset to exec https://gist.github.com/79d5fe1050bbb0e2fac8 (7157). The actual data that falls into the database is https://gist.github.com/df49d4a9707660b8b60b (6765). I don’t understand how such truncation of data is technically possible, since the entire query is sent to MySQL (otherwise, an SQL syntax error would appear).

echo "UPDATE `chemicals` SET `monograph` = {$db->quote($book)} WHERE `id` = {$db->quote($c['id'])};";

If I execute the output (https://gist.github.com/a05fe4c033e74897b82b) using the SQL client, this is the data that gets into the database https://gist.github.com/88870fe26a3ae40e991e (7157, expected).

PDO is initiated using the UTF8 compound.

new PDO('mysql:dbname=[..];host=localhost;charset=utf8', 'root', '[..]', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';"));

UPDATE 2012 07 25 04:11 EST

Now I know that the encoding problem.

$db->exec("UPDATE `chemicals` SET `monograph` = {$db->quote(utf8_decode($book))} WHERE `id` = {$db->quote($c['id'])};");

However, I'm not sure what to do about it. My MySQL connection is already unicode.

/etc/my.cnf .

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
+5
2

. -, UTF8 - , , . -, PHP strlen , .

UTF8.

SHOW CREATE TABLE chemicals;

. my.cnf:

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

MySQL :

MySQL

+1

, . . /. iso-8859-1 .

. , , PDO::ATTR_EMULATE_PREPARES TRUE.

0

All Articles