93 users online (0 members and 93 guests)  


  Results 1 to 4 of 4

Related

  1. Replies: 1
  2. Restoring MySQL Database After Crash    Forum: PHP Forum
    Replies: 5
  3. How to connect to database mysql    Forum: Databases
    Replies: 1
  4. Connecting to Mysql Database    Forum: Databases
    Replies: 3
  5. Replies: 4
  1. #1
    Capo's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Aug 2002
    Location
    USA
    Posts
    69

    Clearing out MYSQL database?

    I have an mysql database with a whole bunch of data from an old forum on it, how do I clear it out before I add my new forum to it?

    Thanks!

  2. #2
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    do you not wish to import the data, or is an importer just not available?

    If you have phpmyadmin you can just delete the tables.

    Dave
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  3. #3
    sonofmidi's Avatar

    Status
    Offline
    Join Date
    Jan 2001
    Location
    NC, USA
    Posts
    75
    This will drop all tables in a given db.

    <?php

    // Open connection to db

    $db_connect = mysql_connect('localhost','username','password');
    mysql_select_db('db_name',$db_connect);

    // Get tables and loop thru and drop

    $num_tables = mysql_list_tables('db_name');

    while($row = mysql_fetch_row($num_tables))
    {
    $delete_table = mysql_query("DROP TABLE IF EXISTS $row[0]");

    if($delete_table)
    {
    echo 'Successfully removed ' . $row[0] . '<br>';
    }
    else
    {
    echo 'Unable to remove ' . $row[0] . '<br>';
    }
    }

    // Free result set and close db connection

    mysql_free_result($num_tables);
    mysql_close($db_connect);

    ?>

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    * copies and pastes into sql toolbox *

    Nice script!
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread