我一直在试图做一个项目,我需要上传信息到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