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
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..

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.