PHP插入15k行和2个for循环

PHP插入15k行和2个for循环,php,mysql,database,Php,Mysql,Database,我希望你能帮我一点忙。我有一个包含653*24个对象的JSON文件,我想将这些对象添加到本地数据库(PHPMyAdmin,Mysql)。 我写了两个for循环(第一个1-654,第二个0-24),在这些循环中,我必须在6个不同的表中插入信息。我这样做了,但问题是循环没有插入所有~15k行,只有~200行,然后浏览器上的加载符号中断,插入停止,没有错误消息 我想,插入的内容对系统来说太多了,但我不知道,所以希望你们能给我一个答案/解决方案来解决这个问题 for($i = 1; $i < 65

我希望你能帮我一点忙。我有一个包含653*24个对象的JSON文件,我想将这些对象添加到本地数据库(PHPMyAdmin,Mysql)。 我写了两个for循环(第一个1-654,第二个0-24),在这些循环中,我必须在6个不同的表中插入信息。我这样做了,但问题是循环没有插入所有~15k行,只有~200行,然后浏览器上的加载符号中断,插入停止,没有错误消息

我想,插入的内容对系统来说太多了,但我不知道,所以希望你们能给我一个答案/解决方案来解决这个问题

for($i = 1; $i < 654; $i++) {
    for($j = 0; $j < 24; $j++) {
         *do 6 inserts here*
    }
}
PHP

$db=$this->getServiceLocator()->get('db');
$k=1;
$dataArray=[];
对于($i=1;$i<11;$i++){
对于($j=0;$j<24;$j++){
$json=file\u get\u contents('https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject={%22第%22页:'.$i'}');
$obj=json_decode($json);
$id=$k;
//德布雷
$playerArray=array(“特征”=>array(),
“club”=>数组(),
“国家”=>数组(),
“防御”=>array(),
“盘带”=>数组(),
“守门员”=>数组(),
“league”=>数组(),
“速度”=>array(),
“传递”=>array(),
“物理”=>array(),
“播放器”=>array(),
“rating”=>array(),
“射击”=>array());
$traitArray=array();
$specialitiesArray=array();
$SpecialLimageArray=array();
$attributeArray=array();
foreach($obj->items[$j]->traits as$value){
数组\u push($traitArray,$value);
}
$traitArray=内爆(“,”,$traitArray);
foreach($obj->items[$j]->specialities as$value){
数组推送($specialitiesArray,$value);
}
$specialitiesArray=内爆(“,”,$specialitiesArray);
foreach($obj->items[$j]->speciallimages as$value){
数组\推送($SpecialLimageArray,$value);
}
如果($SpecialLimageArray[0]!=NULL)$obj->items[$j]->headshotImgUrl=$SpecialLimageArray[0];
foreach($obj->items[$j]->属性为$key){
数组推送($attributeArray,$key->value);
}
阵列推送($playerArray['characteristics',阵列(
“0”=>$obj->items[$j]->firstName,
“1”=>$obj->items[$j]->lastName,
“2”=>$obj->items[$j]->commonName,
“3”=>$obj->项目[$j]->年龄,
“4”=>$obj->项目[$j]->高度。“厘米”,
"5" => "",
"6" => "",
"7" => "",
“8”=>$obj->items[$j]->头像图,
“9”=>$obj->项目[$j]->位置,
“10”=>$obj->项目[$j]->评级,
“11”=>ucfirst($obj->items[$j]->quality),
“12”=>ucfirst($obj->items[$j]->color),
“13”=>obj->items[$j]->技能移动,
“14”=>$obj->items[$j]->weakFoot,
“15”=>$obj->项目[$j]->英尺,
“16”=>$obj->items[$j]->atkWorkRate./“$obj->items[$j]->defWorkRate,
“17”=>$traitArray,
“18”=>$specialitiesArray
));
阵法推送($playerArray['league',阵法(
“0”=>$obj->项目[$j]->联盟->名称,
“1”=>$obj->道具[$j]->联盟->修道院名称,
"2" => ""
));
阵列推送($playerArray['nation],阵列(
“0”=>$obj->项目[$j]->国家->名称,
“1”=>$obj->items[$j]->nation->imageURL->large
));
阵列推送($playerArray['club',阵列(
“0”=>$obj->项目[$j]->俱乐部->名称,
“1”=>$obj->items[$j]->club->ImageURL->normal->large
));
阵法推送($playerary['defensing',阵法(
“0”=>$attributeArray[4],
“1”=>obj->items[$j]->拦截,
“2”=>$obj->items[$j]->标题准确性,
“3”=>$obj->项目[$j]->标记,
“4”=>$obj->items[$j]->standingtackle,
“5”=>$obj->items[$j]->slidingtackle
));
阵列推送($playerary['dribbling',阵列(
“0”=>$attributeArray[3],
“1”=>obj->items[$j]->敏捷性,
“2”=>$obj->项目[$j]->余额,
“3”=>obj->items[$j]->反应,
“4”=>obj->items[$j]->ballcontrol,
“5”=>obj->items[$j]->运球
));
阵型推送($playeray[‘守门员’),阵型(
“0”=>$obj->items[$j]->GKD,
“1”=>obj->items[$j]->gkhandling,
“2”=>$obj->items[$j]->GKK,
“3”=>$obj->items[$j]->GK反射,
“4”=>obj->items[$j]->sprintspeed,
“5”=>$obj->items[$j]->gkpositioning
));
阵列推送($playerary['pace'],阵列(
“0”=>$attributeArray[0],
“1”=>obj->items[$j]->加速,
“2”=>obj->items[$j]->sprintspeed
));
阵列推送($playerArray['passing',阵列(
“0”=>$attributeArray[3],
“1”=>obj->items[$j]->vision,
“2”=>$obj->i
https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject={%22page%22:1}
$db = $this->getServiceLocator()->get('db');
$k = 1;
$dataArray = [];

        for($i = 1; $i < 11; $i++) {
            for($j = 0; $j < 24; $j++) {

                $json = file_get_contents('https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject={%22page%22:' . $i . '}');

                $obj = json_decode($json);

                $id = $k;

                //dbArray
                $playerArray = array("characteristics" => array(),
                    "club" => array(),
                    "nation" => array(),
                    "defending" => array(),
                    "dribbling" => array(),
                    "goalkeeper" => array(),
                    "league" => array(),
                    "pace" => array(),
                    "passing" => array(),
                    "physical" => array(),
                    "player" => array(),
                    "rating" => array(),
                    "shooting" => array());

                $traitArray = array();
                $specialitiesArray = array();
                $specialImageArray = array();
                $attributeArray = array();

                foreach($obj->items[$j]->traits as $value) {
                    array_push($traitArray, $value);
                }
                $traitArray = implode(", ", $traitArray);

                foreach($obj->items[$j]->specialities as $value) {
                    array_push($specialitiesArray, $value);
                }
                $specialitiesArray = implode(", ", $specialitiesArray);

                foreach($obj->items[$j]->specialImages as $value) {
                    array_push($specialImageArray, $value);
                }

                if($specialImageArray[0] != NULL) $obj->items[$j]->headshotImgUrl = $specialImageArray[0];

                foreach($obj->items[$j]->attributes as $key) {
                    array_push($attributeArray, $key->value);
                }

                array_push($playerArray['characteristics'], array(
                    "0" => $obj->items[$j]->firstName,
                    "1" => $obj->items[$j]->lastName,
                    "2" => $obj->items[$j]->commonName,
                    "3" => $obj->items[$j]->age,
                    "4" => $obj->items[$j]->height . " cm",
                    "5" => "",
                    "6" => "",
                    "7" => "",
                    "8" => $obj->items[$j]->headshotImgUrl,
                    "9" => $obj->items[$j]->position,
                    "10" => $obj->items[$j]->rating,
                    "11" => ucfirst($obj->items[$j]->quality),
                    "12" => ucfirst($obj->items[$j]->color),
                    "13" => $obj->items[$j]->skillMoves,
                    "14" => $obj->items[$j]->weakFoot,
                    "15" => $obj->items[$j]->foot,
                    "16" => $obj->items[$j]->atkWorkRate . " / " . $obj->items[$j]->defWorkRate,
                    "17" => $traitArray,
                    "18" => $specialitiesArray
                ));

                array_push($playerArray['league'], array(
                    "0" => $obj->items[$j]->league->name,
                    "1" => $obj->items[$j]->league->abbrName,
                    "2" => ""
                ));

                array_push($playerArray['nation'], array(
                    "0" => $obj->items[$j]->nation->name,
                    "1" => $obj->items[$j]->nation->imageUrls->large
                ));

                array_push($playerArray['club'], array(
                    "0" => $obj->items[$j]->club->name,
                    "1" => $obj->items[$j]->club->imageUrls->normal->large
                ));

                array_push($playerArray['defending'], array(
                    "0" => $attributeArray[4],
                    "1" => $obj->items[$j]->interceptions,
                    "2" => $obj->items[$j]->headingaccuracy,
                    "3" => $obj->items[$j]->marking,
                    "4" => $obj->items[$j]->standingtackle,
                    "5" => $obj->items[$j]->slidingtackle
                ));

                array_push($playerArray['dribbling'], array(
                    "0" => $attributeArray[3],
                    "1" => $obj->items[$j]->agility,
                    "2" => $obj->items[$j]->balance,
                    "3" => $obj->items[$j]->reactions,
                    "4" => $obj->items[$j]->ballcontrol,
                    "5" => $obj->items[$j]->dribbling
                ));

                array_push($playerArray['goalkeeper'], array(
                    "0" => $obj->items[$j]->gkdiving,
                    "1" => $obj->items[$j]->gkhandling,
                    "2" => $obj->items[$j]->gkkicking,
                    "3" => $obj->items[$j]->gkreflexes,
                    "4" => $obj->items[$j]->sprintspeed,
                    "5" => $obj->items[$j]->gkpositioning
                ));

                array_push($playerArray['pace'], array(
                    "0" => $attributeArray[0],
                    "1" => $obj->items[$j]->acceleration,
                    "2" => $obj->items[$j]->sprintspeed
                ));

                array_push($playerArray['passing'], array(
                    "0" => $attributeArray[3],
                    "1" => $obj->items[$j]->vision,
                    "2" => $obj->items[$j]->crossing,
                    "3" => $obj->items[$j]->freekickaccuracy,
                    "4" => $obj->items[$j]->shortpassing,
                    "5" => $obj->items[$j]->longpassing,
                    "6" => $obj->items[$j]->curve
                ));

                array_push($playerArray['physical'], array(
                    "0" => $attributeArray[5],
                    "1" => $obj->items[$j]->jumping,
                    "2" => $obj->items[$j]->stamina,
                    "3" => $obj->items[$j]->strength,
                    "4" => $obj->items[$j]->aggression
                ));

                array_push($playerArray['shooting'], array(
                    "0" => $attributeArray[1],
                    "1" => $obj->items[$j]->positioning,
                    "2" => $obj->items[$j]->finishing,
                    "3" => $obj->items[$j]->shotpower,
                    "4" => $obj->items[$j]->longshots,
                    "5" => $obj->items[$j]->volleys,
                    "6" => $obj->items[$j]->penalties
                ));

                array_push($playerArray['rating'], array(
                    "0" => "",
                    "1" => "",
                    "2" => "",
                    "3" => "",
                    "4" => "",
                    "5" => "",
                    "6" => ""
                ));

                array_push($playerArray['player'], array(
                    "0" => "",
                    "1" => "",
                    "2" => "",
                    "3" => "",
                    "4" => "",
                    "5" => "",
                    "6" => "",
                    "7" => $obj->items[$j]->isGK
                ));
$values = array(
                        ':id'               => $id,
                        ':charFirstname'    => $playerArray["characteristics"][0][0],
                        ':charLastname'     => $playerArray["characteristics"][0][1],
                        ':charCommonname'   => $playerArray["characteristics"][0][2],
                        ':charAge'          => $playerArray["characteristics"][0][3],
                        ':charHeight'       => $playerArray["characteristics"][0][4],
                        ':charNation'       => $playerArray["nation"][0][0],
                        ':charClub'         => $playerArray["club"][0][0],
                        ':charLeague'       => $playerArray["league"][0][0],
                        ':charPicture'      => $playerArray["characteristics"][0][8],
                        ':charPosition'     => $playerArray["characteristics"][0][9],
                        ':charRating'       => $playerArray["characteristics"][0][10],
                        ':charQuality'      => $playerArray["characteristics"][0][11],
                        ':charColor'        => $playerArray["characteristics"][0][12],
                        ':charSkill'        => $playerArray["characteristics"][0][13],
                        ':charWeak_foot'    => $playerArray["characteristics"][0][14],
                        ':charStrong_foot'  => $playerArray["characteristics"][0][15],
                        ':charWorkrates'    => $playerArray["characteristics"][0][16],
                        ':charTraits'       => $playerArray["characteristics"][0][17],
                        ':charSpecialities' => $playerArray["characteristics"][0][18]);
array_push($dataArray, $values);
$k++;
                }
            }
foreach($dataArray as $values) {

                $data[] = '("' . $values[':id'] . '", "' . $values[':charFirstname'] . '",
                            "' . $values[':charLastname'] . '", "' . $values[':charCommonname'] . '",
                            "' . $values[':charAge'] . '", "' . $values[':charHeight'] . '",
                            "' . $values[':charNation'] . '", "' . $values[':charClub'] . '",
                            "' . $values[':charLeague'] . '", "' . $values[':charPicture'] . '",
                            "' . $values[':charPosition'] . '", "' . $values[':charRating'] . '",
                            "' . $values[':charQuality'] . '", "' . $values[':charColor'] . '",
                            "' . $values[':charSkill'] . '", "' . $values[':charWeak_foot'] . '",
                            "' . $values[':charStrong_foot'] . '", "' . $values[':charWorkrates'] . '",
                            "' . $values[':charTraits'] . '", "' . $values[':charSpecialities'] . '")';
            }

            $query = 'INSERT INTO characteristics (id, firstname, lastname, commonname, age, height, nation, club, league, picture, position, rating, quality, color, skill, weak_foot, strong_foot, workrates, traits, specialities) VALUES' . implode(',', $data);

            $stmt = $db->createStatement($query);
            $stmt->prepare($query);
            $results = $stmt->execute(array(
                ':id'               => $id,
                ':charFirstname'    => $playerArray["characteristics"][0][0],
                ':charLastname'     => $playerArray["characteristics"][0][1],
                ':charCommonname'   => $playerArray["characteristics"][0][2],
                ':charAge'          => $playerArray["characteristics"][0][3],
                ':charHeight'       => $playerArray["characteristics"][0][4],
                ':charNation'       => $playerArray["nation"][0][0],
                ':charClub'         => $playerArray["club"][0][0],
                ':charLeague'       => $playerArray["league"][0][0],
                ':charPicture'      => $playerArray["characteristics"][0][8],
                ':charPosition'     => $playerArray["characteristics"][0][9],
                ':charRating'       => $playerArray["characteristics"][0][10],
                ':charQuality'      => $playerArray["characteristics"][0][11],
                ':charColor'        => $playerArray["characteristics"][0][12],
                ':charSkill'        => $playerArray["characteristics"][0][13],
                ':charWeak_foot'    => $playerArray["characteristics"][0][14],
                ':charStrong_foot'  => $playerArray["characteristics"][0][15],
                ':charWorkrates'    => $playerArray["characteristics"][0][16],
                ':charTraits'       => $playerArray["characteristics"][0][17],
                ':charSpecialities' => $playerArray["characteristics"][0][18]
            ));
$query = "INSERT INTO characteristics (
        id, firstname, lastname, commonname, age, height, nation, club, league,
        picture, position, rating, quality, color, skill, weak_foot, strong_foot,
        workrates, traits, specialities
    ) VALUES (
        :id, :charFirstname, :charLastname, :charCommonname, :charAge, :charHeight,
        :charNation, :charClub, :charLeague, :charPicture, :charPosition, :charRating, 
        :charQuality, :charColor, :charSkill, :charWeak_foot, :charStrong_foot, 
        :charWorkrates, :charTraits, :charSpecialities
    )";
$stmt = $db->prepare($query);
for ($i = 1; $i < 11; $i++) {
    $json = file_get_contents('https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject={%22page%22:' . $i . '}');
    $obj = json_decode($json);
    for ($j = 0; $j < 24; $j++) {
        //set up your player array
        $results = $stmt->execute(array(
            ':id'               => $id,
            ':charFirstname'    => $playerArray["characteristics"][0][0],
            ':charLastname'     => $playerArray["characteristics"][0][1],
            ':charCommonname'   => $playerArray["characteristics"][0][2],
            ':charAge'          => $playerArray["characteristics"][0][3],
            ':charHeight'       => $playerArray["characteristics"][0][4],
            ':charNation'       => $playerArray["nation"][0][0],
            ':charClub'         => $playerArray["club"][0][0],
            ':charLeague'       => $playerArray["league"][0][0],
            ':charPicture'      => $playerArray["characteristics"][0][8],
            ':charPosition'     => $playerArray["characteristics"][0][9],
            ':charRating'       => $playerArray["characteristics"][0][10],
            ':charQuality'      => $playerArray["characteristics"][0][11],
            ':charColor'        => $playerArray["characteristics"][0][12],
            ':charSkill'        => $playerArray["characteristics"][0][13],
            ':charWeak_foot'    => $playerArray["characteristics"][0][14],
            ':charStrong_foot'  => $playerArray["characteristics"][0][15],
            ':charWorkrates'    => $playerArray["characteristics"][0][16],
            ':charTraits'       => $playerArray["characteristics"][0][17],
            ':charSpecialities' => $playerArray["characteristics"][0][18]
        ));
    }
}
 foreach($obj->items[$j]->traits as $value) {
                array_push($traitArray, $value);
 }
$traitArray[] = $obj->items[$j]->traits;
':charFirstname'    => $obj->items[$j]->firstName,
':charLastname'     => $obj->items[$j]->lastName,
// and over points