我有這個php腳本將數據保存到數據庫每小時,我想知道如何在數據保存時添加時間戳。 (還,我應該把在phpMyAdmin的長度/值)在我的表中的列:MySQL在保存數據時添加時間戳
編號,名稱,類型,爲空,則默認
1,時間戳,時間戳,不,CURRENT_TIMESTAMP
2,BTC,浮,是的,NULL
3美元,浮動,是的,NULL
我的腳本:
<?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);
?>
time()是一個PHP函數 –