-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_dolar.php
More file actions
62 lines (39 loc) · 1.04 KB
/
Copy pathapi_dolar.php
File metadata and controls
62 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
$link = mysqli_connect("localhost", "root", "", "sistema");
$url= "https://economia.awesomeapi.com.br/USD-BRL/1?format=json";
$request_headers = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
if (curl_errno($ch))
{
print "Error: " . curl_error($ch);
}
else
{
// Show me the result
($transaction = json_decode($data, TRUE));
if($transaction == true){
echo "conexão Ok";
}else{
echo "Eroor";
}
foreach($transaction as $element){
$element['high'].PHP_EOL;
$dolar = $element['high'];
echo $dolar;
}
curl_close($ch);
}
$inserir = "insert into cotacao_dolar(valor)values('$dolar')";
$resultado = mysqli_query($link,$inserir);
if($resultado = true ){
echo "Inserido no bando de dados";
}else{
echo "Erro ao inserir no banco";
}
?>