0

I have large size array which I want to save directly in mysql database . Before saving, I encode the array using json_encode , but whenever I try to save the data, Error arise.

CDbCommand failed to execute the SQL statement: SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes.

I increase the max_allowed_packet value in /etc/my.cnf and restart MySQL service also but that doesnt work out !!

Kais
  • 1,925
  • 3
  • 23
  • 35
  • 1
    It may help :) http://stackoverflow.com/questions/5688403/how-to-check-and-set-max-allowed-packet-mysql-variable http://stackoverflow.com/questions/8062496/how-to-change-max-allowed-packet-size – Elangovan Sep 02 '16 at 12:43
  • Just how big is this data? And what does the PHP/SQL code look like that is trying to save it? – Simba Sep 02 '16 at 13:41

2 Answers2

1

In xamp/mysql/bin/my.cnf try changing the max_allowed _packet and net_buffer_length to

max_allowed_packet='required size'
net_buffer_length='required size'
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
1

If the JSON size is a problem, you could try making the column a blob, and then compressing (and by a SELECT decompressing) the JSON string with bzip:

http://php.net/manual/en/function.bzcompress.php

This does make the field unsearchable for the SELECT command, so it's not gonna work if you need to search the string via SQL.

Ben Hillier
  • 2,126
  • 1
  • 10
  • 15