This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
102 lines (83 loc) · 2.9 KB
/
install.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
<?php
(@ $config = include_once 'config.php') or die ("There was a problem with you config file. Check it and try again");
$config = json_decode($config,TRUE);
var_dump($config);
if (isset($config['hostname'])) {
$hn = "value = '".$config['hostname']."'";
} else {
$hn = "placeholder = 'enter hostname here'";
}
if (isset($config['username'])) {
$un = "value = '".$config['username']."'";
} else {
$un = "placeholder = 'enter username here'";
}
if (isset($config['password'])) {
$pw = "value = '".$config['password']."'";
} else {
$pw = "placeholder = 'enter password here'";
}
if (isset($config['database'])) {
$db = "value = '".$config['database']."'";
} else {
$db = "placeholder = 'enter database here'";
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
// echo "<pre>";
// var_dump($_POST);
// echo "</pre>";
($files = scandir("MySQL")) or die ("MySQL directory no found.");
$files = array_values(array_diff($files,array(".","..")));
if (empty($files)) {
exit("No files in MySql Directory");
}
create_database($_POST["hostname"],$_POST["username"],$_POST["password"], $_POST["database"]);
$connection = mysqli_connect($_POST["hostname"],$_POST["username"],$_POST["password"],$_POST["database"]);
echo("<pre><br><br><br><br><br><br>");
var_dump($connection);
echo("</pre><br><br><br><br><br><br>");
foreach($files as $file){
$SQL = file_get_contents("MySQL/".$file);
var_dump($SQL);
$result = mysqli_query($connection,$SQL);
var_dump($result);
if($result){
echo $file." Installed <br><br>";
} else {
echo $file." Not Installed. There was a problem <br><br>";
}
// sleep(1);
}
}
function create_database($hostname, $username, $password, $database){
// connect to the MySQL server
$conn = new mysqli($hostname, $username, $password);
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
echo(mysqli_connect_errno());
}
// sql query with CREATE DATABASE
$sql = "CREATE DATABASE `".$database."` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
// Performs the $sql query on the server to create the database
if ($conn->query($sql) === TRUE) {
return(TRUE);
} else {
return(mysqli_connect_error());
}
$conn->close();
}
?>
<form method="POST">
Hostname:
<input type="text" name="hostname" <?php echo $hn ?>>
<br> Username:
<input type="text" name="username" <?php echo $un ?>>
<br> Password:
<input type="text" name="password" <?php echo $pw ?>>
<br> Database:
<input type="text" name="database" <?php echo $db ?>>
<br>
<input type="submit">
<!-- <input type="submit" name="sync" value="SYNC"> -->
</form>