"John Hughes" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I need to rebuild a PHP-mySQL site that has an extensive table > structure. Is there a way to DROP all tables that start with a > certain prefix?
First, use SHOW TABLES FROM db LIKE prefix% to get the table names, then iterate through with DROP TABLE tablename The result will look something like <?php $con = mysql_pconnect("localhost", "user", "pwd") or die("Error connecting: ".mysql_error()); $res = mysql_select_db("dbname", $con) or die("Error selecting database: ".mysql_error()); $query = "SHOW TABLES FROM $dbname LIKE '$prefix%'"; $res = mysql_query($query, $con); while ($row = mysql_fetch_array($res)) { $query = "DROP TABLE {$res[0]}" $ex = mysql_query($query) or echo("Error dropping table {$res[0]}:".mysql_error()); } ?> If you are going to use this repeatedly, I would make this a two-stage endeavor: the first step queries the database and returns a check-box form with all the returned table-names; when submitted, the checked tables are dropped. Hope this helps -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php