a1amattyj Posted March 24, 2008 Share Posted March 24, 2008 hi, ive read up on Delete all tables with same prefix and apparently you cant use a wildcard function when trying to do this with php. Although, do you know of a way to do this? (Delete all tables in mysql which use the prefix set in a variable). thanks. Link to comment https://forums.phpfreaks.com/topic/97603-delete-all-tables-with-same-prefix/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 24, 2008 Share Posted March 24, 2008 Use a query like the following to get a list of matching table names, then loop through the results and delete each one - SHOW TABLES FROM db_name LIKE 'pattern' Link to comment https://forums.phpfreaks.com/topic/97603-delete-all-tables-with-same-prefix/#findComment-499448 Share on other sites More sharing options...
Orio Posted March 24, 2008 Share Posted March 24, 2008 <?php mysql_connect("localhost", "user", "pass"); mysql_select_db("dbname"); $prefix = "tbl"; $result = mysql_query("SHOW TABLES LIKE '{$prefix}%'"); while($table = mysql_fetch_array($result)) mysql_query("DROP TABLE `{$table[0]}`"); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/97603-delete-all-tables-with-same-prefix/#findComment-499494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.