I have this php script to save data to a database hourly, and I was wondering how to add a timestamp when the data is saved. (also, what should I put as Length/Values in phpMyAdmin) The columns in my table are:
Number, Name, Type, Null, Default
1, Timestamp, timestamp, No, CURRENT_TIMESTAMP
2, BTC, float, Yes, NULL
3, USD, float, Yes, NULL
My script:
<?php
$json_url = "https://crypto-trade.com/api/1/ticker/dvc_btc";
$json_data = file_get_contents($json_url);
$json_feed = json_decode($json_data);
$DVCdata = $json_feed->data;
$DVCask = $DVCdata->min_ask;
$json_url1 = "https://api.bitcoinaverage.com/ticker/USD";
$json_data1 = file_get_contents($json_url1);
$json_feed1 = json_decode($json_data1);
$BTCask = $json_feed1->ask;
$DVC_USD = $BTCask * $DVCask;
$DVCround = round($DVC_USD, 8);
$connection = mysqli_connect("mysql.serversfree.com",user,pass,database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($connection,"INSERT INTO database (Timestamp, BTC, USD)
VALUES (???, '$DVCask', '$DVCround')");
mysqli_close($connection);
?>
As your column defaults to CURRENT_TIMESTAMP just take out that field entirely - it will get the default value
mysqli_query($connection,"INSERT INTO database (BTC, USD) VALUES ('$DVCask', '$DVCround')");
Bear in mind it will be the time on the database rather than the webserver if those are different machines and the time is not in sync.