-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabaseOperations.php
161 lines (139 loc) · 4.4 KB
/
databaseOperations.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html>
<?php
include("navbar.php");
$sqlDir = "SQLSave";
//Op
if($_POST['pass'] == "stan"){
//Upload
if($_FILES["fileToUpload"]["name"]){
$uploadOk = 1;
$imageFileType = pathinfo(basename($_FILES["fileToUpload"]["name"]),PATHINFO_EXTENSION);
// Check file size
if ($_FILES["fileToUpload"]["size"] > 100000000) {
//echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "sql" && $imageFileType != "SQL") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
echo $imageFileType;
$uploadOk = 0;
}
if($uploadOk == 1){
//Get contents
$fileContent = file_get_contents($_FILES['fileToUpload']['tmp_name']);
//Ready for query
}
}
//Revert
if($_POST['revert'] == '1'){
//Read dir and get newest file
$newestFile = "";
$newestFileDate = 0;
if (is_dir($sqlDir)){
if ($dh = opendir($sqlDir)){
while (($file = readdir($dh)) !== false){
if($file != "." && $file != ".."){
$fileName = $sqlDir."/".$file;
$fileDate = filemtime($fileName);
if($fileDate > $newestFileDate){
$newestFileDate = $fileDate;
$newestFile = $fileName;
}
}
}
closedir($dh);
}
}
if($newestFile != ""){
$fileContent = file_get_contents($newestFile);
}
}
//Run Query
if(isset($fileContent)){
//Save old sql to file
$externalUse = True;
include("exportSQL.php");
$saveSQL = Export_Database($mysqlHostName,$mysqlUserName,$mysqlPassword,$DbName, True, $tables , $backup_name=false );
$fname = $sqlDir."/sqlSave".date('m-d-Y-His').".sql";
$SQLFile = fopen($fname , 'w') or die("Unable to write save file (".$fname.")!");
fwrite($SQLFile , $saveSQL);
fclose($SQLFile);
include("databaseName16.php");
$con= mysql_connect($address, $username, $password);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$sql = explode(";;;;;;" , $fileContent);
foreach($sql as &$sqlquery){
if(trim($sqlquery) != ""){
if (!mysql_query($sqlquery,$con)){
echo($sqlquery."<br>");
die('Error: ' . mysql_error());
}
}
}
$con = Null;
echo("Database changed.");
}
}
?>
<head>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap-material-design-master/dist/css/ripples.min.css" rel="stylesheet">
<link href="bootstrap-material-design-master/dist/css/material-wfont.min.css" rel="stylesheet">
<script src="jquery-1.11.2.min.js"></script>
<script src="sorttable.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<style>
#overallForm {
font-size: 15px;
display: inline-block;
}
</style>
<div class="container row-offcanvas row-offcanvas-left">
<div class="well column col-lg-12 col-sm-12 col-xs-12" id="content">
<?php
if($uploadOk == 1){
echo "Report submitted. Please do not refresh this page.<br>";
}
?>
<div class="col-lg-4 col-sm-4 col-xs-12">
<a><h2>Database Upload </h2></a>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<b><text class=" control-label" >Password</text></b>
<div class="col-lg-10">
<input type="password" class="form-control" id="pass" name="pass" placeholder=" ">
</div>
</div>
<br>
Upload SQL file.
<input type="file" name="fileToUpload" multiple id="fileToUpload">
<input id="uploadFleSubmit" type="submit" class="btn btn-primary" value="Submit Data" onclick="" >
</form>
</div>
<div class="col-lg-4 col-sm-4 col-xs-12">
<a><h2>Export Database</h2></a>
<a href="exportSQL.php" class="btn btn-raised btn-primary">Download File</a>
</div>
<div class="col-lg-4 col-sm-4 col-xs-12">
<a><h2>Revert To Previous</h2></a>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<b><text class=" control-label" >Password</text></b>
<div class="col-lg-10">
<input type="password" class="form-control" id="pass" name="pass" placeholder=" ">
</div>
</div>
<input type="hidden" name="revert" value="1">
<input id="revertSubmit" type="submit" class="btn btn-primary" value="Revert" onclick="" >
</form>
</div>
</div>
</div>
</body>
</html>