1

我正在尝试使用 PHPExcel 将数据从 excel 上传到 MySQL 数据库。我的代码在 localhost 中运行良好,但是在服务器中它正在将数据从 excel 更新到数据库,但控件没有退出循环(没有终止进程)。相同的代码适用于 3000 行但不适用于 40000 行的 excel 文件。请帮我

foreach($sheetData as $str)
    {

        if($z == $chunk_s)
        {
            break;
        }
        $z++;
        if($i == 1)
        {
            $i++;
            $val1 = $str['A'];
            $val2 = $str['B'];
            $val3 = $str['C'];
            $val4 = $str['D'];
            $val5 = $str['E'];
            $val6 = $str['F'];
            $val7 = $str['G'];
            $val8 = $str['H'];
            $val9 = $str['I'];
            $val10 = $str['J'];
            //$val11 = $str['K'];
            $val12 = $str['K'];
            $val13 = $str['L'];
            $val14 = $str['M'];
            $val15 = $str['N'];
            $val16 = $str['O'];
            $val17 = $str['P'];
            $val18 = $str['Q'];
            $val19 = $str['R'];
            $val20 = $str['S'];
            $val21 = $str['T'];

            if($val1 == "Order Date" && $val2 == "No" && $val3 == "Customer No." && $val4 == "Bill-to Name" && $val5 == "Bill-to Contact" && $val6 == "Phone No." && $val7 == "Bill-to City" && $val8 == "E-Mail" && $val9 == "Item No." && $val10 == "Description" && $val12 == "Maximum Agreed Repair Amount" && $val13 == "Status" && $val14 == "Your Reference" && $val15 == "Fault Code" && $val16 == "Resolution Code" && $val17 == "CHAWAGO Code" && $val18 == "Expected Finishing Date" && $val19 == "Amount Including VAT" && $val20 == "Posted Invoice No." && $val21 == "AirWay Bill No.")
            {
            }
            else
            {
                echo "Invalid Excel File.";
                break;
            }
        }
        else
        {       
            $i++;   
            $val1 = $str['A'];
            $val2 = $str['B'];
            $val3 = $str['C'];
            $val4 = $str['D'];
            $val5 = $str['E'];
            $val6 = $str['F'];
            $val7 = $str['G'];
            $val8 = $str['H'];
            $val9 = $str['I'];
            $val10 = $str['J'];
            $val11 = "";
            $val12 = $str['K'];
            $val13 = $str['L'];
            $val14 = $str['M'];
            $val15 = $str['N'];
            $val16 = $str['O'];
            $val17 = $str['P'];
            $val18 = $str['Q'];
            $val19 = $str['R'];
            $val20 = $str['S'];
            $val21 = $str['T'];

            if($val1 == "END OF THE RECORD")
            {
                echo "End of the record is reached!<br /><br />";

                echo "<br />Number of New Records Added : " . $j . "<br />";
                echo "<br />Number of Updated Records  : " . $l . "<br />";
                echo "<br /><a href=''>Click here to go home.</a></pre>";
                exit;

                //break;
            }

            if($val1 == "" && $val2 == "" && $val3 == "" && $val4 == "" && $val5 == "" && $val6 == "" && $val7 == "" && $val8 == "" && $val9 == "" && $val10 == "" && $val12 == "" && $val13 == "" && $val14 == "" && $val15 == "" && $val16 == "" && $val17 == "" && $val18 == "" && $val19 == "" && $val20 == "" && $val21 == "")
            {
                echo "Blank row occurred. Please remove all the blank rows and start uploding the file.<br /><br />";
                echo "<br />Number of New Records Added : " . $j . "<br />";
                echo "<br />Number of Updated Records  : " . $l . "<br />";
                echo "<br /><a href=''>Click here to go home.</a></pre>";
                exit;
            }
            else
            {
                $res1 = mysql_query("select * from servicedetails where Number = '$val2' and Customer_No = '$val3'");
                $num = mysql_num_rows($res1);
                if($num == 0)
                {                
                    $res = mysql_query("INSERT INTO servicedetails (Order_Date, Number, Customer_No, Bill_to_Name, Bill_to_Contact, Phone_No, Bill_to_City, EMail, Item_No, Description, Repair_Status_Code, Maximum_Agreed_Repair_Amount, Status, Your_Reference, Fault_Code, Resolution_Code, CHAWAGO_Code, Expected_Finishing_Date, Amount_Including_VAT, Posted_Invoice_No, AirWay_Bill_No) VALUES ('$val1', '$val2', '$val3', '$val4', '$val5', '$val6', '$val7', '$val8', '$val9', '$val10', '$val11', '$val12', '$val13', '$val14', '$val15', '$val16', '$val17', '$val18', '$val19', '$val20', '$val21')");         
                    $j++;
                    if($j > $chunk_s)
                    {
                        echo "<br />Number of New Records Added : " . $j . "<br />";
                        echo "<br />Number of Updated Records  : " . $l . "<br />";
                        echo "<br /><a href=''>Click here to go home.</a></pre>";
                        exit;
                    }
                }
                else
                {
                    $res = mysql_query("update servicedetails set Status = '$val13' where Number = '$val2' and Customer_No = '$val3'");
                    $l++;
                    if($l > $chunk_s)
                    {
                        echo "<br />Number of New Records Added : " . $j . "<br />";
                        echo "<br />Number of Updated Records  : " . $l . "<br />";
                        echo "<br /><a href=''>Click here to go home.</a></pre>";
                        exit;
                    }
                }
            }
        }
    }
4

1 回答 1

0

很难说。

  • 可能数据太多?
  • 脚本超出 php 内存?
  • MySQL 因调用过多而终止?
  • 您的任何行都有价值$val1 == "END OF THE RECORD吗?
  • 说什么$sheetdata.size();

你说

控制没有退出循环(没有终止进程)

你说的控制是什么意思?

于 2013-03-29T11:30:43.310 回答