PHP SQLite3查询INSERT,DELETE&重定向

时间:2011-09-22 11:24:33

标签: php sqlite

我花了最近几天的时间来解决使用PHP脚本作为保存按钮的简单概念。当从网页按下该按钮时,该按钮会将数据从table A插入table B,然后删除table A并重定向到我的主index.html

<?php
try {
    $db = new PDO('sqlite:/srv/db/data.db');
}

    $db->exec("INSERT * INTO Archive FROM resultstbl");
    $db->exec("DELETE * FROM resultstbl") 
 unset($db);
?>

到目前为止,我可以使用这个PHP查询的一些帮助,以及任何指导。

1 个答案:

答案 0 :(得分:1)

我会做这样的事情:

<?

if(isset($_POST['but1'])) // this checks if the button is clicked
{
   $db = new PDO('sqlite:/srv/db/data.db');  // I assume this is working fine
   $db->exec("INSERT INTO Archive SELECT * FROM resultstbl"); // tables must be equivalent in terms of fields
   $db->exec("DELETE FROM resultstbl") // You want to delete the records on this table or the table itself? This deletes the records

   header("Location: index.php?page=home"); // This will only work if you didn't output anything to the screen yet. If you displayed something it will fail
   die();

}

?>

<form action="sql.php" method="POST"> <!-- Assuming this page is sql.php -->

   <input type="submit" name="but1" value="GO!"/>
</form>

您可以在此处检查SQLite的插入和删除语句的语法:

http://www.sqlite.org/lang_insert.html

http://www.sqlite.org/lang_delete.html