我的php腳本插入數據到數據庫不起作用。它也沒有給出任何錯誤信息,所以我不知道什麼是錯的。哪裏不對?PHP MySQL數據插入不工作
我的表:
Number Name Type Null Default
1 Timestamp timestamp No CURRENT_TIMESTAMP
2 BTC float Yes NULL
3 USD float Yes 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 (BTC, USD)
VALUES ('$DVCask', '$DVCround')");
mysqli_close($connection);
?>
你檢查,看是否'mysqli_query'返回什麼?你看看是否mysqli_error()返回任何東西嗎? – andrewsi
我希望你的'mysqli_connect()'參數只是虛擬變量,以掩飾真實值?由於語法顯然是錯誤的。 –
FLOAT?你確定?!!? – Strawberry