-
Notifications
You must be signed in to change notification settings - Fork 0
/
getdatabtcstats.php
76 lines (63 loc) · 1.53 KB
/
getdatabtcstats.php
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
63
64
65
66
67
68
69
70
71
72
73
<?php
include 'config.php';
$json = file_get_contents('https://blockchain.info/stats?format=json');
$decoded1 = json_decode($json);
// Store cache
file_put_contents('btcmarquee.json', serialize($decoded1));
// Retrieve cache
$decoded1 = unserialize(file_get_contents('btcmarquee.json'));
$decoded = $decoded1;
$btcmarkprice = $decoded->market_price_usd;
$btchashrate = $decoded->hash_rate;
$btctotalfees = $decoded->total_fees_btc;
$btcnmined = $decoded->n_btc_mined;
$btcblocksmined = $decoded->n_blocks_mined;
$btctotalblocks = $decoded->n_blocks_total;
$btctradevol = $decoded->trade_volume_usd;
$btctransvol = $decoded->estimated_transaction_volume_usd;
$btcblocksize = $decoded->blocks_size;
$btcminersrev = $decoded->miners_revenue_usd;
$btcdifficulty = $decoded->difficulty;
$btctradevolbtc = $decoded->trade_volume_btc;
$minutesblocks = $decoded->minutes_between_blocks;
// Attempt insert query execution
$sql = "
INSERT INTO btcstats (
btcmarkprice,
btchashrate,
btctotalfees,
btcnmined,
btcblocksmined,
btctotalblocks,
btctradevol,
btctransvol,
btcblocksize,
btcminersrev,
btcdifficulty,
btctradevolbtc,
minutesblocks
)
VALUES (
'$btcmarkprice',
'$btchashrate',
'$btctotalfees',
'$btcnmined',
'$btcblocksmined',
'$btctotalblocks',
'$btctradevol',
'$btctransvol',
'$btcblocksize',
'$btcminersrev',
'$btcdifficulty',
'$btctradevolbtc',
'$minutesblocks'
)
";
if(mysqli_query($link, $sql)){
echo "";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>