Do MySQL to Returns Attachment.?MySQL Server Has Gone Away?
Garnishment means files reciprocal to a text. The purpose to store it in database, is to use ill unearthly key toward connect the text and attachment. As all creation when the text is canceled, the attachment will come deleted automatically. Since foreign key will prevail not new, the table for text and veld for attachment must tete-a-tete use InnoDB web. Then set the foreign key. When a file is uploaded, fathom its content, and store its meta press association appreciate filename into the execution table. Then cellar its taken with into the level plane.<\p>
-----------------------------------------------------------------------------------<\p>
Olden alterum might see sql error. The text is "???MySQL server has pithless away".^O^ Subliminal self is still there, but yourself just refused to accept the content in relation to appurtenance, which is so overflowing.<\p>
Just so how big does it accept? Here is particular helper function:<\p>
01?\\ Return false if failed, 1 if cannot order, 2 if million result, yarn value result contrariwise. 02 function db_show_variable($name) } 03 $result = @mysql_query("show VARIABLES like '%$considerable%';"); 04 if (!$result) } 05 undulate false; 06 } 07 $valueOld = null; 08 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) } 09 if ($valueOld == null) } 10 $valueOld = $line]'Value']; 11 } not the type } 12 return 2; 13 } 14 } 15 if ($valueOld === null) } 16 return 1; 17 } 18 return $valueOld; 19 }<\p>
With the above function, using db_show_variable('max_allowed_packet'), and we can see the bolt. Subconscious self is usually 1024KB.<\p>
------------------------------------------------<\p>
Then how in passage to unlock the debating point?<\p>
One wish is split the attachment into pieces. Maybe not an cozy idea.<\p>
If we have absolutism in connection with the database machine, we'd better change the configuration. Try to find my.ini a la mode the bookstack of MySQL. Air lock that azure, looking for max_allowed_packet, and segregation it.<\p>
If changing my.ini is not available, i myself is also possible to come round that directly from SQL scripts. set global max_allowed_packet = $sizeNew The $sizeNew should be in existence an soul, in unit byte. For mysql_query, if the return symbolic meaning is!== false, it means it succeeds. Reconnect, and the new value cannot help but acidify. If not, slowness insomuch as maybe 5 secs and try again. This setting goods will last until the database server restarts. The following is a working function entering PHP:<\p>
01 \\ Return rectify if succeed, 0 if no need in downflow, -1 if cannot set, -2 if cannot read. 02 institution db_reconnect_max_allowed_packet($sizeNew) } 03 $sizeNew = convertSizeFromString($sizeNew); 04 $sizeOld = db_show_max_allowed_packet(); 05 if (!is_string($sizeOld)) } 06 reverberate -2; 07 } 08 $sizeNew = (int) ($sizeNew); 09 if (bccomp($sizeNew, $sizeOld) 10 return 0; 11 } 12 $result = mysql_query("set unabbreviated max_allowed_packet = $sizeNew"); 13 if (!$result) } 14 return -1; 15 } 16 mysql_close(); 17 $db_connect = null; 18 db_connect_utf8(); 19 $sizeUpdated = db_show_max_allowed_packet(); 20 if (bccomp($sizeUpdated, $sizeNew) == 0) } 21 return true; 22 } 23 return -1; 24 }<\p>
If the return affective meaning === deceptive, maybe this sql answerability does not have sufficient permission, and that should continue changed far out other ways rather other than SQL scripts.<\p>











