Uaing php to drop mysql tables within a mysql database using php and mysql

Hi there,

I am wanting to drop some tables have the script do it automatically its showing a blank page this is my php script i have atm


$sql = "SHOW Tables FROM $dbname";
$result = mysqli_query($con,$sql);
if (!$result)
{
	echo "DB Error, could not list tables\
";
	echo 'MySQL Error: ' . mysqli_error($con);
	exit;
}
while ($row = mysqli_fetch_row($result))
{
	$d=$row[0];
	echo $d;
	//
	$r="DROP TABLE {$row[0]}";
	echo $r;
	$rs=mysqli_query($con,$r);
	if(!$rs)
	{
		echo "Error".mysqli_error($con);
	}
	else
	{
		echo "Database $row has been emptied";	
	}
	//
	//echo "\
";
}
mysqli_free_result($result);

What am i doing wrong??

Why do you want such unusual thing?

i am setting up some php scripts that will empty the database every 30 minutes for demo so people can play around with the code and when they come back 30 mins later it will be re-installed.

Safer ways to do this are to restore a master SQL file backup on a timed basis.

DROP deletes a table. TRUNCATE empties it.

can i do that same way i run a php file as a cronjob?

Yes, you can cron php scripts.

You don’t need php script for this.
just mysql binary to restore sql dump, as Paul said.
something like
mysql < /path/to/dump.sql