Causes MySQL server has gone away method and reason

Source: Internet
Author: User

Today when I write a data import came out of the MySQL tutorial server has gone away first glance thought is the database tutorial hangs, but other normal, looks for the data from the website to discover, because the SQL statement is too long, thus surpasses the max_allowed_packet size, If this is the case, the SQL statement is carefully instrumented as follows:

while ($rs = Mysql_fetch_array ($query))

{

$os = Autoaddlink ($os);

Insert .... Data preservation,

}

Functions are as follows

function Autoaddlink ($STR)
{
$spath = ' {cmspath} ';
$sql = "Select Typename,id,typedir from 3g_arctype where topid<>175";
$query = mysql_query ($sql) or Die (Mysql_error ());
$tmps Tutorial tr = strtolower ($STR);

while ($rs = Mysql_fetch_array ($query))
{
$rs [' typename '] = Strtolower (Str_replace (' Mobile theme ', ', ', Str_replace (' theme ', ', ', Str_replace (' Nokia ', ', $rs [' TypeName ']));
$tmpstr =str_replace ($rs [' TypeName '], "<a href=". Str_replace ($spath, ', $rs [' Typedir ']). " > ". $rs [' TypeName ']." </a> ", $TMPSTR);

}
return $tmpstr;
}

From the face code not careful to see is not always found, we see

$os = Autoaddlink ($os);

Insert .... Data preservation,

If it is not a problem to put the while loop alone, if it is possible to import SQL too long, the reason why I do not say that a variable lifetime problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.