Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Conexao com banco de dados
- require_once("classes/Database.class.php");
- $pdo = Database::conexao();
- // Tipos de veículos disponíveis na FIPE
- $array = ["motos", "carros", "caminhoes"];
- foreach ($array as $vehicle) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://fipeapi.appspot.com/api/1/".$vehicle."/marcas.json");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $output = curl_exec($ch);
- curl_close($ch);
- $output = json_decode($output);
- foreach ($output as $chave) {
- $get = "SELECT fipe_key FROM fipe_marcas WHERE fipe_key = '".$chave->key."'";
- $get = $pdo->query($get);
- $count = $get->rowCount();
- if($count == 0){
- $destaque = 0;
- $tipo = $vehicle;
- $create = date("Y-m-d H:i:s");
- $update = date("Y-m-d H:i:s");
- $sql = "INSERT INTO fipe_marcas (fipe_id, name, fipe_name, fipe_order, fipe_key, tipo, destaque, created_at, updated_at)
- VALUES (:fipe_id, :name, :fipe_name, :fipe_order, :fipe_key, :tipo, :destaque, :created_at, :updated_at)";
- $stmt = $pdo->prepare($sql);
- $stmt->bindParam(':fipe_id', $chave->id, PDO::PARAM_INT);
- $stmt->bindParam(':name', $chave->name, PDO::PARAM_STR);
- $stmt->bindParam(':fipe_name', $chave->fipe_name, PDO::PARAM_STR);
- $stmt->bindParam(':fipe_order', $chave->order, PDO::PARAM_STR);
- $stmt->bindParam(':fipe_key', $chave->key, PDO::PARAM_STR);
- $stmt->bindParam(':tipo', $tipo, PDO::PARAM_STR);
- $stmt->bindParam(':destaque', $destaque, PDO::PARAM_STR);
- $stmt->bindParam(':created_at', $create, PDO::PARAM_STR);
- $stmt->bindParam(':updated_at', $update, PDO::PARAM_STR);
- $stmt->execute();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement