How to improve execution efficiency

Source: Internet
Author: User
How to improve execution efficiency

for ($i =0; $i
{
$var = Explode (",", $r [$i]);
$barcode = $var [0];
$num = $var [1];
$sql = "INSERT into". $t. " ' (Barcode,num) VALUES (' ". $barcode." ', ' ". $num." ') ";
echo $sql. '
';
mysql_query ($sql);
}


A total of more than 6,000 records, if each record is executed insert into, consumes a long time, more than the default of 90s. Is there any way to improve execution efficiency?

Share to:


------Solution--------------------
You can insert an array into an array first, and then insert it uniformly


for ($i =0; $i
{
$var = Explode (",", $r [$i]);
$barcode = $var [0];
$num = $var [1];
$sql [] = "('". $barcode. "', '". $num. "')"; /write to SQL array
}
mysql_query (' insert INTO '. $t. ' (barcode,num) values '. Implode (', ', $sql));
Unified Insert

------Solution--------------------
Citation:
error message:
Maximum execution time of seconds exceeded


Time-outs can be added on top of the head
Set_time_limit (0);
?>
  • Related Article

    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.