0

I have a web application. When upload an image to server I has converted that to base64 string, but when I inserted that to database is show an error "MySQL server has gone away". Because image string is to long, I think. So I tried using "$compressed = gzdeflate($param['image'], 9);" to compess that but not success. Anyone can help me to fixed it ?

Thanks for your time ?

khavq
  • 41
  • 1
  • 7
  • Avoid uploading images directly into the database, instead store the image in a folder and save the path to the folder/image into the database. But, if you have to save it, you can use BLOB type or, as you want it, use TEXT. – Andrei Jun 08 '15 at 09:50
  • Hi Andrew, I using Text – khavq Jun 08 '15 at 09:52
  • How long are your compressed string and table attribute in which you are storing BASE64 string? Have you compared there sizes?? – Hassaan Salik Jun 08 '15 at 09:57
  • [See this](http://stackoverflow.com/questions/12425287/mysql-server-has-gone-away-when-importing-large-sql-file) in that case. – Andrei Jun 08 '15 at 09:57
  • Hi Hassan Salik, my string is 2883183 and compared return is null – khavq Jun 08 '15 at 10:25

1 Answers1

0

The MySQL server has gone away (error 2006) has two main causes and solutions:

  • Server timed out and closed the connection. To fix, check that “wait_timeout” mysql variable in your my.cnf configuration file is large enough.
  • Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection.

To fix, you can increase the maximal packet size limit max_allowed_packet in my.cnf file, eg. set max_allowed_packet = 128M, then sudo /etc/init.d/mysql restart.

The max_allowed_packet variable can be set globally by running a query.

SET GLOBAL max_allowed_packet=1073741824;

To change the setting for everyone until the server restarts

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75