-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_db.php
70 lines (64 loc) · 1.77 KB
/
delete_db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require 'config.php';
$parser = new PEAR2\Console\CommandLine(array(
'description' => 'Deletes MySQL database',
'version' => '0.0.1', // the version of your program
));
$parser->addOption(
'interactive',
array(
'short_name' => '-i',
'long_name' => '--interactive',
'description' => 'Run interactively',
'action' => 'StoreTrue'
)
);
$parser->addOption(
'name',
array(
'short_name' => '-n',
'long_name' => '--name',
'description' => 'database name',
'action' => 'StoreString',
'help_name' => 'database_name'
)
);
try {
$result = $parser->parse();
if ($result->options["interactive"]){
//TODO Запуск в интерактивном режиме
}
if (empty(array_filter($result->options))){
$parser->displayUsage();
}
try {
$conn = new mysqli($mysql_settings["client"]["host"], $mysql_settings["client"]["user"], $mysql_settings["client"]["password"]);
} catch (Exception $ex) {
echo "Service unavailable: ".$ex->getMessage()."\n";;
exit(1);
}
$sql = "DROP DATABASE ".$result->options["name"];
try {
if ($conn->query($sql) === TRUE) {
echo "Successfully deleted database: ".$result->options["name"]."\n";
$conn->close();
exit(0);
}
else{
throw new Exception($conn->error);
}
} catch (Exception $ex) {
echo "Error: ".$ex->getMessage()."\n";;
$conn->close();
exit(1);
}
$conn->close();
}
catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}