Skip to content

Instantly share code, notes, and snippets.

@vozhukh
Created January 18, 2017 14:43
Show Gist options
  • Save vozhukh/783d7150536531f8b9008f19446b43ca to your computer and use it in GitHub Desktop.
Save vozhukh/783d7150536531f8b9008f19446b43ca to your computer and use it in GitHub Desktop.
Видадення файлів і БД
<?php
/*
Важливо!!!
передпочатком зробити копію dbconn.php та .settings.php!!!
Копія даних файлів не зберігається
*/
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/dbconn.php");
if (!mysql_connect($DBHost, $DBLogin, $DBPassword)) {
print 'Could not connect to mysql';
exit;
}
$result = mysql_list_tables($DBName);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
$arTable= array();
while ($row = mysql_fetch_row($result)) {
$arTable[]= $row[0];
print "Table: $row[0]\n";
}
mysql_free_result($result);
unset ($result);
if (count($arTable)>0){
$query="DROP TABLE ".implode(', ',$arTable);
if(mysql_connect($DBHost, $DBLogin, $DBPassword)){echo('файно');}else{echo(' не дуже добре');}
$result = mysql_query($query) or die ("гм, щось пишішло не так!");
mysql_free_result($result);
}
echo "Результат видалення таблиць БД - ".$result;
// запуск рекурсивного видалення відносно корню сайту.
// Якщо потрібно видалити все (і сам сервер!!!) тоді запустити так - rrmdir("."); , ДАНИЙ спосіб не рокомендовано
rrmdir($_SERVER["DOCUMENT_ROOT"]."/");
//Another simple way to recursively delete a directory that is not empty:
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if ( $object=='clear.php') continue; // включення щоб себе не видалити
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment