code_junkie

Can I change the packet size DBD::mysql uses

Nov 13th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. DBD::mysql::st execute failed: Got a packet bigger than 'max_allowed_packet' bytes
  2.  
  3. $data = "whatever data needs inserting";
  4. my $ins_sth=$dbh->prepare("insert into table_name (datacol) values(?)");
  5. my $upd_sth=$dbh->prepare("update table_name set datacol=datacol||? where id=?");
  6. my $max_size = 900_000; # Really max_packet_size - 200bytes
  7. my $pos = 0;
  8. $ins_sth->execute(substr($data,$pos,$max_size));
  9. my $id = $dbh->{'mysql_insertid'};
  10. $pos += $max_size;
  11. while ( $pos < length($data) ) {
  12. $upd_sth->execute(substr($data,$pos,$max_size));
  13. $pos+=$max_size;
  14. }
Add Comment
Please, Sign In to add comment