我一直在試圖做一個項目,我需要上傳信息到sqlite3數據庫。爲此我使用簡單的PHP腳本。PHP到sqlite3 - 無法上傳
我成功地從PHP腳本到數據庫已經上傳信息像這樣的東西:
<?php
try
{
$db = new PDO('sqlite:mydatabase.db');
$db->exec("INSERT INTO temps (zone,temperature) VALUES ('maia',77)");
echo "Row Inserted\n";
}
catch(PDOException $e)
{
print $e->getMessage();
}
?>
現在我在努力做同樣的腳本謊言是:
<?php
$data = htmlspecialchars($_GET["temp1"]);
$file = "temps.txt";
$current = file_get_contents($file);
$current .= $data;
file_put_contents($file, $current);
try
{
$db = new PDO('sqlite:teste1.db');
$db->exec('BEING;');
$db->exec('INSERT INTO temps (temperature) VALUES ($temp1)');
$db->exec('COMMIT;');
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
我表「temps」有這樣的模式:
CREATE TABLE temps (temperature NUMERIC);
是因爲var類型在t他是PHP,因爲我把它聲明爲數據庫中的數字?如果是這樣,我該如何解決?
欣賞您的所有想法。
謝謝
'$ DB-> EXEC( '是;');'也許應該是'$分貝 - > exec('BEGIN;');'也是'$ db-> exec('INSERT INTO temps(temperature)VALUES($ temp1)');'應該是'$ db-> exec(「INSERT INTO temps(temperature )VALUES($ temp1)「);'。使用單引號是一個文字(所以你不能在裏面使用變量)。 你收到了什麼錯誤? – honerlawd
沒有錯誤。我現在要改變它 –
確保你還添加了編輯我只是做 – honerlawd