SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deleting all tables with mos_ prefix?

    Hey,
    Is there a query I can run in phpMyAdmin to delete all tables with the prefix "mos_"? If there is, please provide the exact query as I can't code mySQL. Thanks.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I don't think there is any way to accomplish that using just one query. The only solution I can come up with is to make a script that obtain the tables with the prefix mos_ (using SHOW TABLES LIKE "mos_%"), and then creates a query which will drop the tables. If you need help what the script, let me know.

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Erik,
    Thanks for the offer - yes, I do need help with the script. I have absolutely no idea whatsoever how to code mySQL

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that something like the script below would work.
    However, backup your database before running it, just in case.

    PHP Code:
    <?php

    mysql_connect
    ('localhost''username''password');
    mysql_select_db('your_database');

    $tables = array();
    $result mysql_query('SHOW TABLES LIKE "mos_%"') or die(mysql_error());

    while(
    $table mysql_fetch_row($result))
      
    $tables[] = $table[0];

    $delete 'DROP TABLE 'implode(','$tables);
    mysql_unbuffered_query($delete) or die(mysql_error());

    ?>
    Yours, Erik.
    Last edited by lilleman; Jan 16, 2005 at 14:17. Reason: Changed the word "query" to "script", and also added a linebreak between the sentences.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2003
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great script! No problems with it and now my DB is all cleaned up
    Thanks alot, lilleman.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •