How to truncate a table, using php / mysql script, mysqli, phpmyadmin?
It’s quite easy, here is the code:
1 2 3 | <?php mysqli_query($connection, "TRUNCATE table_name"); ?> |
You will also need to declare the $connection variable, but I guess that is pretty easy.
So this is how you TRUNCATE a table.
“Truncate” means to empty a table.
It will remove all the entries but it will preserve the table structure.
This can be useful when using cronjobs, first you truncate a table, then you populate it with new values.
Note: you can use the same command in phpmyadmin, just type “TRUNCATE table_name”.
If you know other methods, regarding how to truncate a table in php mysql, please leave them in the comments section.
Other users will definitely appreciate your help.