Created
October 3, 2017 12:41
-
-
Save vozhukh/6a921991fea07bc9f9f7c8155e9fd6ea to your computer and use it in GitHub Desktop.
clear mysqli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Важливо!!! | |
передпочатком зробити копію dbconn.php та .settings.php!!! | |
Копія даних файлів не зберігається | |
*/ | |
function get_tables($connect) | |
{ | |
$tableList = array(); | |
$res = mysqli_query($connect,"SHOW TABLES"); | |
while($cRow = mysqli_fetch_array($res)) | |
{ | |
$tableList[] = $cRow[0]; | |
} | |
return $tableList; | |
} | |
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/php_interface/dbconn.php"); | |
if (!($connect=mysqli_connect($DBHost, $DBLogin, $DBPassword, $DBName))) { | |
print 'Could not connect to mysql'; | |
exit; | |
} | |
$arTable = get_tables($connect); | |
if (count($arTable)>0){ | |
$query="DROP TABLE ".implode(', ',$arTable); | |
$result = mysqli_query($connect,$query) or die ("гм, щось пишішло не так!"); | |
mysqli_free_result($result); | |
}else{ | |
echo "Результат видалення таблиць БД - ".$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