PHP TRUNCATE a Database:

To delete all entries in a table, in a database, you can use this statement. It will delete all rows, but keep the structure of the table. So this is an effective way of doing that, not to loop through, and delete all rows one by one.

If you want to delete a single row, see this example.


TRUNCATE a Database

We return briefly to SQL'ing, to look at an example on how to delete all content in a table. ..
So now we have filled up our table 'contacts' with a lot of tests. We are ready to use the database for real things, and we want to delete every row in the table.
How is that done?
Here is a solution that deletes everything without messing up the structure.

As you see in the above example deleting all content is quite simple. Again SQL is our friend and provide the TRUNCATE with which we can clean out the table.


    $con=mysqli_connect('', 'root', 'Your_Password', 'dbname'); 
    if (mysqli_connect_errno()) { 
        echo "Error connecting to DB"; 
    mysqli_query($con, 'TRUNCATE TABLE contacts'); 
Icons made by Freepik from This example will show you how to remove all content from a table, using the TRUNCATE query