SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    united states
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL server has gone away...

    I am using PHP to load images into the following table:

    CREATE TABLE image_data (
    Image_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
    Type TINYINT UNSIGNED default '1' NOT NULL,
    ContentType VARCHAR(255) NOT NULL,
    Image LONGBLOB NOT NULL,
    Size INT UNSIGNED NOT NULL,
    Width INT UNSIGNED NOT NULL,
    Height INT UNSIGNED NOT NULL,
    PRIMARY KEY (Image_ID)
    ) ENGINE=MYISAM DEFAULT CHARSET=latin1;

    Once I read an image file using:
    PHP Code:
    $file_size filesize($file);
    $imageFile  addslashes(fread(fopen($file"r"), $file_size)); 
    I store it in the database using:
    UPDATE image_data SET Type = $type, Image = '{$imageFile}', Size = '{$file_size}' WHERE Image_ID = $imageDataID;

    This seems to work fine for many images, but I get the following error when I try it on a certain file:
    "MySQL server has gone away".
    When I don't set the Image attribute in the statement, everything is fine. It seems like either the Image attribute value for this file is corrupted, or maybe it is too big to transfer...

    The file's size is 1,224KB.
    Does anyone know what could be wrong?

    thanks in advance

  2. #2
    This is all Mumbo Jumbo Amit's Avatar
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using the addcslashes with / instead of addslahes.

    Personally, I would recommend encoding using base64_encode and then saving.

    But beware this may increase the processing time a bit.

    HTH!

  3. #3
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is a bit late and all :P but I had this problem on my server with attachments, and the MySQL going away is because you're trying to give it a query that's too big. In the MySQL ini you have to add a line like
    max_allowed_packet=16M
    or however big you need so that it will allow queries larger than the default 1M. Enjoy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •