Last active
February 8, 2021 04:31
-
-
Save Santiago-j-s/971c562dedb6d0c44bbdd40a99c0e172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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