TP5 自毁类

<?php
namespace app\admin\controller;

use think\Db;
use app\common\controller\Common;
use think\Config;
class Delete extends Common{

	/**
	 * 直接删除数据库
	 * @return [type] [description]
	 */
	public function delete_base () {
		$sql = "show tables";
		$re = Db::query($sql);

		$d = Config::get('database');
		$d = $d['database'];
		$result = Db::execute('drop database '.$d);
        dump($result);   
	}


	/**
	 * 删除所有表
	 * @return [type] [description]
	 */
	public function delete_table () {
		//获取所有的表
		$sql = "show tables";
		$re = Db::query($sql);

		$d = Config::get('database');
		$d = $d['database'];
		$s = 'Tables_in_' . $d;
		//halt($re);
		//转换为索引数组
		$data = [];
		foreach ($re as $index => $item) {
		    //$r=strpos($item[$s],'fa_basic');
		   	
		    $result = Db::execute('DROP TABLE IF EXISTS '.$item[$s]);  //删除所有表

		    array_push($data, $result);
		    
		}

		halt($data);

	}

	/**
	 * 清空所有数据
	 */
	public function delete_data () {
		//获取所有的表
		$sql = "show tables";
		$re = Db::query($sql);

		$d = Config::get('database');
		$d = $d['database'];
		$s = 'Tables_in_' . $d;
		//halt($re);
		//转换为索引数组
		$data = [];
		foreach ($re as $index => $item) {
		    //$r=strpos($item[$s],'fa_basic');
		   	
		    $result = Db::execute('TRUNCATE TABLE '.$item[$s]);  //删除所有表

		    array_push($data, $result);
		    
		}

		halt($data);

	}

	/**
	 * 删除所有项目
	 * @return [type] [description]
	 */
	public function delete_dir() {
		  
		  $dir = realpath('.');
			
		  if(!$handle=@opendir($dir)){
		  //检测要打开目录是否存在
		  die("没有该目录");
		  }
		  while(false!==($file=readdir($handle))){
		    if($file!=="."&&$file!==".."){
		    //排除当前目录与父级目录
		    $file=$dir .DIRECTORY_SEPARATOR. $file;
		    if(is_dir($file)){
		     deletedir($file);
		    }else{
		     if(@unlink($file)){
		      echo "文件<b>$file</b>删除成功。<br>";
		     }else{
		      echo "文件<b>$file</b>删除失败!<br>";
		     }
		    }
		    }
		    if(@rmdir($dir)){
		    echo "目录<b>$dir</b>删除成功了。<br>\n";
		    }else{
		    echo "目录<b>$dir</b>删除失败!<br>\n";
		    }
		   }
	}
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值