Is there a command to empty a table?
or would I just use a SQL statement in conjunction with a query statement?

If so is this the correct syntax

$table = "abc";
$sql = "DELETE FROM $table WHERE *";
mysql_query($sql);

Would that delete every row in table abc?

Thanks, Regards X

PS: Also is it possible to have this automated so at X time of each hour, day, week, etc it is done?

Recommended Answers

Make a script with something like:

$table="abc";
mysql_query("TRUNCATE $table");

This removes all entries from the table and resets the auto-increment to 0.

You could setup a Cron Job to run the script at set intervals.

Edit: Not recommended if you are using transactions as this …

Jump to Post

All 3 Replies

If so is this the correct syntax

$table = "abc";
$sql = "DELETE FROM $table WHERE *";
mysql_query($sql);

Below is the correct syntax:

$table = "abc";
$sql = "DELETE FROM `".$table."`";
mysql_query($sql);

Make a script with something like:

$table="abc";
mysql_query("TRUNCATE $table");

This removes all entries from the table and resets the auto-increment to 0.

You could setup a Cron Job to run the script at set intervals.

Edit: Not recommended if you are using transactions as this is not able to be rolled back.

commented: Thanks for the reminder. +1

cwarn ya just in a rush, thanks.

xan what is a cron job so I can automate the truncate command as I plan to use that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.