How to Delete All Rows of a MySQL Table Using PHP



PHP







In this article, we show how to delete all rows of a MySQL table using PHP.

In other words, we are completely clearing all records from the table and wiping it blank.

The table will still exist, because we're deleting the table itself. But we are deleting all rows (or all records) of the table.

This can be used if we want the table structure but just want to clear all records from the table.

The general format of the MySQL query to delete all rows of a MySQL table is shown below. It uses the MySQL TRUNCATE keyword.



So the following code above deletes all rows from the table named table_name.

We'll now show how to tie this in with PHP.



So, first, we must connect to the database.

After we do this, we create a variable named $truncatetable. This $truncatetable variable is set equal to a mysql_query() function that has the parameter "TRUNCATE TABLE table_name". This deletes all rows (or records) of the table named table_name.

So this is how you can delete all rows from a MySQL table using PHP.


Related Resources

How to Delete a MySQL Table Using PHP

How to Delete a Column of a MySQL Table Using PHP

How to Delete a Row of a MySQL Table Using PHP

HTML Comment Box is loading comments...