Jump to content

PHP - Droping & Emtpying unknown tables


tsilenzio

Recommended Posts

Ok on my site for some reason if i dont emtpy a database then when i drop it and recreate it, it will have all the entrys still in it. So i was wondering if somone could help me determine some kind of script that will figure out how many tables there are, then emtpy them, after that drop the tables or is this impossible? :(

 

- deathseaker

 

Thanx in advance!

Link to comment
https://forums.phpfreaks.com/topic/61573-php-droping-emtpying-unknown-tables/
Share on other sites

well here is the verzion i came up with...

 

<?php
require_once('config.php');

$result = mysql_list_tables($db_database);

if (!$result)
{
    print "DB Error, could not list tables\n";
    print 'MySQL Error: ' . mysql_error();
    exit;
}


while ($row = mysql_fetch_row($result))
{
    $table = row[0];
    $query = "TRUNCATE TABLE '$table'";
    processQuery($query);
    $query = "DROP TABLE '$table'";
    processQuery($query);
       
}
?>

 

processQuery connects to the database and does all that stuff for me..

why?

you can dump the whole database off a single line (or delete it) instead of dumping all the data

also why truncate and then dump

just dump

also its more standard to do

$result = mysql_list_tables($db_database) or die(mysql_error());

saves you code and same result

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.