function addTeams($con, $comp, $teams) { $current = array(); foreach ($comp->selectTeams($con) as $team) { array_push($current, $team->Number); // printf("%s %s %s %s %s\n", // $team->Number, $team->Name, $team->City, $team->State, $team->Country); } foreach ($teams as $team) { if (!in_array($team->Number, $current)) { printf("Adding %s to %s\n", $team->Number, $comp->Name); $st = team::selectTeam($con, $team->Number); if (!$st) { printf("New team: {$team->Number}, {$team->Name}, {$team->City}, {$team->State}, {$team->Country}\n"); team::insertTeam($con, (array) $team); } $comp->insertTeam($con, $team->Number); } else { printf("Team %s to already added.\n", $team->Number); } } }
break; case JSON_ERROR_STATE_MISMATCH: $error = 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $error = 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $error = 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: $error = 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; } throw new Exception($error); } $homepage = file_get_contents('teams.json'); $teams = json_decode($homepage, true, 5); json_last_error_msg(); // var_dump($teams); $con = DB::connect(); foreach ($teams as $team) { $st = team::selectTeam($con, $team['Number']); if (!$st) { printf("Missing: %s, %s, %s\n", $team['Number'], $team['Name'], $team['City']); team::insertTeam($con, $team); } // else { // var_dump($st); //} }