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