TP5 自毁类

    xiaoxiao2023-10-22  166

    <?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)