https://dev.webpages.dk/  
 
PHP TRUNCATE a Database
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

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.

 PHP

<?php
    $con=mysqli_connect('127.0.0.1', 'root', 'Your_Password', 'dbname'); 
    if (mysqli_connect_errno()) { 
        echo "Error connecting to DB"; 
    } 
    mysqli_query($con, 'TRUNCATE TABLE contacts'); 
    mysqli_close($con); 
 ?>
Icons made by Freepik from www.flaticon.com This example will show you how to remove all content from a table, using the TRUNCATE query
09:04:48