This question has been deleted and is no more available to answer.
2
I am creating a website and its almost ready. I want to empty all the tables to retest the website. How to empty all the tables in MySql database with PHP?

Share using link:

Direct share:

Nov 29 at 17:29:40
Alex
Alex
291

2 Answers

2
To empty the table we use the following SQL statement:

TRUNCATE TABLE table_name;

So in your case you are using PHP:

mysql_query("TRUNCATE TABLE table_name");

And to empty all the tables:

mysql_query("TRUNCATE TABLE table_name1");
mysql_query("TRUNCATE TABLE table_name2");
mysql_query("TRUNCATE TABLE table_name3");
mysql_query("TRUNCATE TABLE table_name4");
...

Note: The table_name is the name of your table(s). If you are using mysqli then you should use mysqli_query(" ... "" );.

Hope it will help!!!
Nov 29 at 17:38:6
Abdul
Abdul
192

Thanks abdul. It solved my problemAlex Reado Nov 29 at 17:43:40

1
You can empty the table by simply using the following query:

mysql_query("DELETE FROM tablename");
mysql_query("DELETE FROM tablename1");
mysql_query("DELETE FROM tablename2");
mysql_query("...");

or if you are using mysqli:

mysqli_query("DELETE FROM tablename");
mysqli_query("DELETE FROM tablename1");
mysqli_query("DELETE FROM tablename2");
mysqli_query("...");

tablename is the name of your table(s).
Nov 29 at 17:42:54
Muhammadbilal
Muhammadbilal
85

Waoo, this one is also simple and we are using in daily life. Thanks!!!Alex Reado Nov 29 at 17:44:1

Asked
11 days ago
Viewed
18 times