MySQL, CONCAT, the result is null after a while -
im putting big data table, longblob
field, table grows, field becomes empty. code:
mysql_query ('create table if not exists testtable (content longblob not null) engine = myisam'); mysql_query('truncate table testtable'); mysql_query('replace testtable values (".")'); $bigdata = str_repeat('a', 1024*1024*2); // 2 mb! foreach (str_split($bigdata, 1024*64) $item) { mysql_query ('update testtable set content = concat(content, "'.mysql_real_escape_string($item).'")'); $rec = mysql_fetch_row(mysql_query ('select content testtable')); echo 'size of content: '.strlen($rec[0]).'<br>'; }
the output:
size of content: 65537 size of content: 131073 size of content: 196609 size of content: 262145 size of content: 327681 size of content: 393217 size of content: 458753 size of content: 524289 size of content: 589825 size of content: 655361 size of content: 720897 size of content: 786433 size of content: 851969 size of content: 917505 size of content: 983041 size of content: 0 size of content: 65536 size of content: 131072 size of content: 196608
whats happening? longblob should take more data that.
increase max_allowed_packet
size.
it looks failing @ 1mb, , according https://dev.mysql.com/doc/refman/5.5/en/packet-too-large.html default max packet size 1mb:
the server's default max_allowed_packet value 1mb. can increase if server needs handle big queries
set value in my.cnf
file, e.g.:
[mysqld] max_allowed_packet=16m
in php
if don't have access mysql config try setting via query (note: i've not checked if work).
$db->query( 'set @@global.max_allowed_packet = 16777216' );
Comments
Post a Comment