三里屯摇滚 发表于 2011-06-04 15:54

在php中实现MySql相同前缀数据表的批量删除

在php中实现MySql相同前缀数据表的批量删除<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>?

action=kill">
<table width="425" border="0" align="center">
<tr>
    <td height="46" colspan="2" align="center"><p>批量删除MySQL数据库相同前缀的数

据表&nbsp;by <a href="http://www.3ppt.com" target="_blank">sudu8</a></p></td>
    </tr>
<tr>
    <td width="103">ip地址</td>
    <td width="306" height="26"><label>
      <input name="ip" type="text" id="ip" value="localhost" />
    </label></td>
</tr>
<tr>
    <td height="25">数据库账号</td>
    <td height="26"><label>
      <input type="text" name="user" id="user" />
    </label></td>
</tr>
<tr>
    <td>数据库密码</td>
    <td height="26"><label>
      <input type="text" name="pass" id="pass" />
    </label></td>
</tr>
<tr>
    <td>数据库</td>
    <td height="26"><label>
      <input type="text" name="db" id="db" />
    </label></td>
</tr>
<tr>
    <td>要删除的前缀</td>
    <td height="26">    <label>
      <input type="text" name="qz" id="qz" />
    </label>(&nbsp;例如:bbs_&nbsp;&nbsp;)</td>
</tr>
    <tr>
    <td height="67" colspan="2" align="center">    <label>
      <input type="submit" name="tijiao" id="tijiao" value="开始删除" />
</label></td>
    </tr>
</table>
</form>
<?phpif(@$_GET["action"]=="kill"){

if (empty($_POST['ip']))
echo "您没有填写IP地址";
echo "<br>";
if (empty($_POST['user']))
echo "您没有填写用户名";
echo "<br>";
if (empty($_POST['pass']))
echo "您没有填写密码";
echo "<br>";
if (empty($_POST['db']))
echo "您没有填写数据库";
echo "<br>";
if (empty($_POST['qz']))
echo "您没有填写前缀";
echo "<br>";

$ip=$_POST['ip'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$db=$_POST['db'];
$qz=$_POST['qz'];

$conn=mysql_connect($ip,$user,$pass);
if (!$conn){
die ("数据库连接出错! www.3ppt.com ");
}
mysql_connect($ip,$user,$pass);

mysql_select_db($db);

$rs=mysql_query('show tables');

while($arr=mysql_fetch_array($rs)){

    $TF=strpos($arr,$qz);

   if($TF===0){

      $FT=mysql_query("drop table $arr");

         if($FT){

             echo "$arr 删除成功!<br>";
       }

            }

            }

}

?>

中天人 发表于 2011-06-08 14:25

火速围观!牛人招PHP技术员-出得厅堂,下得厨房,进得洞房!有木有!!有木有!!

http://bbs.phpchina.com/thread-214382-1-1.html   这公司太有才了,做PHP的还要求会武功,找金庸大师学学吧,笑死俺了哈

csona 发表于 2011-06-09 20:19

这程序写.....

辣椒封 发表于 2011-06-11 23:09

火速围观!牛人招PHP技术员-出得厅堂,下得厨房,进得洞房!有木有!!有木有!!

http://bbs.phpchina.com/thread-214382-1-1.html   这公司太有才了,做PHP的还要求会武功,找金庸大师学学吧,笑死俺了哈

亮图标 发表于 2011-06-12 16:19

火速围观!牛人招PHP技术员-出得厅堂,下得厨房,进得洞房!有木有!!有木有!!

http://bbs.phpchina.com/thread-214382-1-1.html   这公司太有才了,做PHP的还要求会武功,找金庸大师学学吧,笑死俺了哈
页: [1]
查看完整版本: 在php中实现MySql相同前缀数据表的批量删除