Cara menggunakan php sqlite3 delete

SQLite DELETE Query
To delete the existing records from a table, the DELETE query is used in SQLite.

Show

Syntax:

DELETE FROM table_name  
WHERE conditions;

Example 1:
TEACHERS Table:

ID NAME SUBJECT
1 Jim English
2 John Geology
3 Watson French
4 Holmes Chemistry
5 Tony Physics

Example:

DELETE FROM TEACHERS 
WHERE ID = 2;

Explanation:
Here we have deleted the row from an already existing table “TEACHERS” where ID is 2. To verify the table data execute the below query.
SELECT * FROM TEACHERS;

Output:

ID NAME SUBJECT
1 Jim English
3 Watson French
4 Holmes Chemistry
5 Tony Physics

Example 2:

Explanation:
Here we have deleted all the rows from an already existing table “TEACHERS”, but not the table itself. To verify the table data execute the below query.
SELECT * FROM TEACHERS;

Cara menggunakan php sqlite3 delete

SQL DELETE Keyword


The DELETE command is used to delete existing records in a table.

The following SQL statement deletes the customer "Alfreds Futterkiste" from the "Customers" table:

Example

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

Try it Yourself »

Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!

It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:

The following SQL statement deletes all rows in the "Customers" table, without deleting the table. This means that the table structure, attributes, and indexes will be intact:



I've spent the last couple of days grappling wit the simple concept of using a php script as Save button. When pressed from a webpage the button will INSERT data from table A to table B then delete table A and redirect to back to my main index.html.

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

So far I could use some help with this PHP query, as well as any guidance.

asked Sep 22, 2011 at 11:24

I would do something like this:

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();

}

?>

You can check the syntax for the insert and delete statments for SQLite here:

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

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

answered Sep 22, 2011 at 11:47

Luís SousaLuís Sousa

781 silver badge7 bronze badges

3