更新记录时PHP异常终止程序

时间:2013-11-12 12:30:01

标签: php mysql

我正在使用制表符分隔的.txt文件更新数据库中的8000条记录。我的代码只更新了前5506条记录,并在终止后没有任何错误。下次刷新页面时,它会更新5500条记录。我没有对代码进行任何更改。我失踪的地方?我的代码是:

$result = mysqli_query($con,"SELECT id FROM `TABLE 1` ");
    for($i=1;$i<=$rows;$i++)
    {
        $flag=0;
       //$result = mysqli_query($con,"SELECT id FROM `TABLE 1` ");
    try
    {
       while($row = mysqli_fetch_array($result))
       {

         //echo $cols[$i][0];

            $v=strval($cols[$i][0]);
            if(strcmp($row['id'],$v)==0)//id exists in database=> update
            {
                echo "update";
                 echo "<br>".$row['id']."  ".$cols[$i][0];
                //echo "<br>".$row['price']."  ".$cols[$i][4];
                //echo"<br> ".$cols[$i][4];

                $uq="UPDATE `TABLE 1` SET `condition`='".$cols[$i][3]."',`price`='".$cols[$i][4]."',`availability`='".$cols[$i][5]."',`link`='".$cols[$i][6]."',`image_link`='".$cols[$i][7]."',`Gender`='".$cols[$i][11]."',`size`='".$cols[$i][13]."',`Color`='".$cols[$i][14]."',`material`='".$cols[$i][15]."',`shipping_weight`='".$cols[$i][16]."' where `id`='$v'";
                //mysqli_query($con,"UPDATE `TABLE 1` SET `price`='".$cols[$i][4]."'  WHERE `id`='$v'");
                //echo $cols[$i][0];
                $d=mysqli_query($con,$uq);
                if($d)
                {
                   echo"updated sucessfully";
                }
                else
                {
                    echo"not inserted";
                   die('Error:'. mysqli_error($con));
                }


            $flag=1;
            break;
           } 

        }     

    }
        catch(Exception $e)
            {
               echo $e->getMessage();
               $flag=1;
            }

2 个答案:

答案 0 :(得分:1)

您可以尝试通过将此代码添加到脚本顶部来启用display_errors:

ini_set('display_errors', 1);
error_reporting(E_ALL);

如果这没有帮助,您可以检查您的php错误日志。

答案 1 :(得分:0)

重置最长执行时间,因为程序似乎执行了很长时间,并检查代码中是否存在任何无限循环,如果不是删除它。

ini_set('max_execution_time', 600); //600 seconds = 10 minutes
相关问题