WordPress.org

Ready to get started?Download WordPress

Forums

Droping Database Tables. (3 posts)

  1. cron
    Member
    Posted 8 years ago #

    I have recently upgraded to wp 2.0 from wp 1.5 and I would like to delete ALL the info in my SQL tables and start over again. Since I do not have acess to PhpMyAdmin or similar programs I have decided to write a php script that would deleate all the info in my tables. So far I have:

    <?php
    // Connect to database
    $connect = mysql_connect('localhost', 'USERNAME', 'PASSWORD')
    or die('Could not connect: ' . mysql_error());
    echo 'Connected successfully';
    // Select Database
    mysql_select_db('DATABASE') or die('Could not select database')

    // Deleating
    $delete = 'WTF GOES HERE?';
    $result = mysql_query($delete) or die('Failed to delete: ' . mysql_error());

    // Close Connection
    mysql_close($connect);
    ?>

    my question is what should go in the $delete place to acomplish this?

  2. skulled
    Member
    Posted 8 years ago #

    Depending on how familiar you are with the mysql functions in PHP, you have two options:

    1. Get the list of all the tables that you have in the database manually, and then run the following as your $delete:

    $delete = "DROP TABLE TABLENAME";

    2. Take a look here:

    http://se.php.net/manual/en/function.mysql-list-tables.php

    And then write out a loop to run through all the tables found in your database, and run a similar $delete command for each table.

    Hope this helps. Be CAREFUL and BACKUP your database before you do this, since it cannot be reversed, and if something goes wrong you should still have your data.

  3. cron
    Member
    Posted 8 years ago #

    Ok, sounds good, now to see if it works as sugested. I will post my results here.

    Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.