Skip to content

Instantly share code, notes, and snippets.

@Santiago-j-s
Last active February 8, 2021 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Santiago-j-s/971c562dedb6d0c44bbdd40a99c0e172 to your computer and use it in GitHub Desktop.
Save Santiago-j-s/971c562dedb6d0c44bbdd40a99c0e172 to your computer and use it in GitHub Desktop.
<?php
set_time_limit(1000);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.freetogame.com/api/games'
]);
$json = curl_exec($curl);
curl_close($curl);
$juegos = json_decode($json, true);
$pdo = new PDO("sqlite:data.db");
if ($pdo === null) {
throw new \Exception("failed to connect to data.db");
}
foreach ($juegos as $juego) {
$sql = <<<SQL
INSERT INTO juegos (id, title, thumbnail, short_description, game_url, genre, platform, publisher, developer, release_date, freetogame_profile_url)
VALUES (:id, :title, :thumbnail, :short_description, :game_url, :genre, :platform, :publisher, :developer, :release_date, :freetogame_profile_url)
SQL;
$insert = $pdo->prepare($sql);
$insert->execute([
$juego['id'],
$juego['title'],
$juego['thumbnail'],
$juego['short_description'],
$juego['game_url'],
$juego['genre'],
$juego['platform'],
$juego['publisher'],
$juego['developer'],
$juego['release_date'],
$juego['freetogame_profile_url'],
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment