-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.php
More file actions
83 lines (64 loc) · 1.73 KB
/
connect.php
File metadata and controls
83 lines (64 loc) · 1.73 KB
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
<?php
if($_POST["isTest"] == 1){
$conn = new mysqli($_POST["connStr"],$_POST["user"],$_POST["pass"]);
if($conn->connect_error){
echo json_encode([
"alert"=>"Cant Connect to the database Mate!",
"type"=>"err"
]);
}else{
echo json_encode([
"alert"=>"Connection to database successful Cheers!",
"type"=>"success"
]);
}
$conn->close();
}else{
$data = array(
'username' => $_POST["user"],
'password' => $_POST["pass"],
'connectionString' => $_POST["connStr"],
'databaseName' => $_POST["dbName"]
);
$conn = new mysqli($_POST["connStr"],$_POST["user"],$_POST["pass"]);
if($conn->connect_error){
echo json_encode([
"alert"=>"Cant Connect to the database Mate!",
"type"=>"err"
]);
}else{
file_put_contents('json/dbConfig.json', json_encode($data));
$sql = "CREATE DATABASE ".$_POST["dbName"];
if ($conn->query($sql) === TRUE) {
$conn->close();
$conn = new mysqli($_POST["connStr"],$_POST["user"],$_POST["pass"],$_POST["dbName"]);
$sql = "CREATE TABLE standards (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
fathername VARCHAR(30),
email VARCHAR(50),
state VARCHAR(50),
country VARCHAR(50),
reg_date TIMESTAMP
)";
if($conn->query($sql) == TRUE){
echo json_encode([
"alert"=>"Connection to database successful, Database Created!",
"type"=>"success"
]);
}else{
echo json_encode([
"alert"=>"Error creating database: " . $conn->error,
"type"=>"err"
]);
}
}else{
echo json_encode([
"alert"=>"Error creating database: " . $conn->error,
"type"=>"err"
]);
}
$conn->close();
}
}
?>