How to add prefix to all tables?

Discussion in 'MySQL' started by ifyn, Sep 22, 2006.

  1. #1
    Is there a way to prefix all existing tables in mysql without manually altering each one? I am trying to use same database for a multisite, I have a lot of tables which I would like to be prefixed eg with wwp_
     
    ifyn, Sep 22, 2006 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Something like this might work:

    
    // connect to the database
    
    $prefix = "wwp_";
    
    $result = mysql_query("SHOW TABLES");
    
    while($row = mysql_fetch_row($result))
    {
    	$rename = mysql_query("RENAME TABLE " . $row[0] . " TO " . $prefix . $row[0]);
    }
    
    PHP:
     
    SoKickIt, Sep 22, 2006 IP