HTML-Code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$dbname='in_dein_fall_test';
$json_datei='https://api.truckyapp.com/v2/traffic/servers';
$mysqli=mysqli_connect('localhost', 'root', '', 'test');
if (mysqli_connect_errno()) die ("Connect failed: " . mysqli_connect_error());
mysqli_set_charset($mysqli, "utf8");
// /* von hier auskommentieren nach ersten aufruf
// bis hier auskkommentieren oder löschen*/
$query = "INSERT INTO `$dbname` (`name`, `url`, `short`, `game`)
VALUES ('%s','%s','%s', '%s')";
$json = json_decode(file_get_contents($json_datei),true);
$queries = array();
foreach ($json['response'] as $data){
$name=mysqli_real_escape_string($mysqli, $data['name']);
$url=mysqli_real_escape_string($mysqli, $data['url']);
$short=mysqli_real_escape_string($mysqli, $data['short']);
$game=mysqli_real_escape_string($mysqli, $data['game']);
$queries[] = sprintf($query, $name, $url, $short, $game);
}
$menge=count($queries);
if (mysqli_multi_query($mysqli, implode(";", $queries))){
echo "$menge Datensätze erfolgreich importiert<br>";
}else{
echo "Irgendwelche errors<br>";
}
echo "";
$mysqli->close();
?>
Kommentar