返回列表 回复 发帖

查看数据库的信息,可以删除表等

  1. <?php
  2. session_start();
  3. echo "<style type=text/css>body,td,input {background-color:&#35;eeeeee; font-size:12px; font-family:verdana}</style>";
  4. if (!IsSet(&#36;host) )
  5. {
  6.     echo "<center><form action=&#36;PHP_SELF method=post>
  7.     请输入数据库的信息:<P>
  8.     数据库主机 : <input name=host value=localhost><p>
  9.     数据库用户名: <input name=user><p>
  10.     数据库密码 : <input name=pass><p>
  11.     数据库名字 : <input name=db_name><p>
  12.     <input type=submit>
  13.     </from></center>";
  14. }
  15. else
  16. {
  17.     session_register("host");
  18.     session_register("user");
  19.     session_register("pass");
  20.     session_register("db_name");
  21.    
  22.     &#36;linkid = mysql_connect(&#36;host, &#36;user, &#36;pass);
  23.     if ( !IsSet(&#36;table_prefix) )
  24.     {   
  25.         &#36;result = mysql_list_tables(&#36;db_name, &#36;linkid);
  26.         while (&#36;data = mysql_fetch_row(&#36;result) )
  27.         {
  28.             list(&#36;table) = &#36;data;
  29.             echo "&#36;table<br>";
  30.         }
  31.         &#36;num = mysql_num_rows(&#36;result);
  32.         echo "<P><font color=red>在数据库 &#36;db_name 中,共有以上 &#36;num 个表</font><P>";
  33.         mysql_free_result(&#36;result);
  34.         
  35.         //以下删除操作没有确认,且不可恢复,请慎重操作!
  36.         echo "<hr><h3><font color=red>请仔细阅读说明,以下删除操作没有确认,且不可恢复,请慎重操作!</font></h3><p>";
  37.         echo "<form action=&#36;PHP_SELF method=post>请输入欲删除表的全名,如想批量删除,请输入欲删除表的前缀。<br>
  38.             比如,你输入 "phpBB_" ,则所有名字以 "phpBB_" 开头的表将会被删除!<br>
  39.             <font color=red>如想删除所有的表请输入 "/" </font><p>
  40.             <input name=table_prefix style="color:red"><input type=submit></form> ";
  41.     }
  42.     else
  43.     {
  44.         if ( &#36;table_prefix == "" ) die("没有输入表名");
  45.         if ( &#36;table_prefix == "/" ) &#36;table_prefix = "";
  46.         //以下是操作数据库 &#36;db_name 的结果:<P>
  47.         echo "以下是操作数据库 &#36;db_name 的结果:<P>";
  48.         &#36;result = mysql_list_tables(&#36;db_name, &#36;linkid);
  49.         while (&#36;data = mysql_fetch_row(&#36;result) )
  50.         {
  51.             list(&#36;table) = &#36;data;
  52.             if ( IsPrefix(&#36;table_prefix, &#36;table) == TRUE )
  53.             {
  54.                 //delete table &#36;table
  55.                 &#36;sql = "drop table &#36;table";
  56.                 if ( mysql_query(&#36;sql) )
  57.                     echo "&#36;table             ------ 删除成功!<P>";
  58.                 else
  59.                     echo "<font color=red>&#36;table             ------ 删除失败!</font><P>";
  60.             }
  61.         }
  62.         mysql_free_result(&#36;result);
  63.         echo "<a href=&#36;PHP_SELF><h2><<回首页</h2></a>";
  64.     }
  65.    
  66.     mysql_close(&#36;linkid);
  67. }
  68. function IsPrefix(&#36;table_prefix, &#36;table)
  69. {
  70.     &#36;len = strlen(&#36;table_prefix);
  71.     &#36;prefix = substr(&#36;table, 0, &#36;len);
  72.     if (&#36;prefix == &#36;table_prefix)
  73.         return TRUE;
  74.     else   
  75.         return FALSE;
  76. }
  77. ?>
复制代码
哈哈哈!!!!你的IP是不是?我都知道了!!!
返回列表