mysql 批量删除表

<?php
set_time_limit(0);
$con = mysql_connect("localhost", "user", "pwd");
$dbname = "db";
if ($con) {
  if (mysql_select_db($dbname, $con)) {
    $sql = "SHOW TABLES WHERE Tables_in_$dbname   LIKE 'prd_%';";
    $ret = mysql_query($sql);
    while($row = mysql_fetch_assoc($ret)){
      $info1[] = $row["Tables_in_$dbname"];
    }
    foreach ($info1 as $val) {
      //表名字$val
      $sql ="drop table $val";
      mysql_query($sql);
    }
  }
}
mysql_close($con);
?>

 

posted on 2017-06-14 19:25  coding-farmer  阅读(201)  评论(0编辑  收藏  举报

导航