This repository has been archived by the owner on May 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
156 lines (123 loc) · 3.2 KB
/
init.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE stocks";
if (mysqli_query($conn, $sql)) {
echo "Database created successfully";
} else {
echo "Error creating database: " . mysqli_error($conn);
}
$dbname = "stocks";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<br/><br/>";
// Create table for users
$sql="CREATE TABLE users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
reg_time TIMESTAMP,
password VARCHAR(30) NOT NULL,
name VARCHAR(50) NOT NULL,
amount FLOAT(15,2) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
// Create table for companies
$sql="CREATE TABLE comp (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
up_time TIMESTAMP,
name VARCHAR(30) NOT NULL,
price FLOAT(15,2) NOT NULL,
pprice FLOAT(15,2) NOT NULL,
decr TEXT(1000) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
// Create table for buying/selling
$sql="CREATE TABLE buysell (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
time TIMESTAMP,
userid INT(30) NOT NULL,
price FLOAT(15,2) NOT NULL,
type INT(2) NOT NULL,
quantity INT(10) NOT NULL,
compid INT(10) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
//Create table for current conditions
$sql="CREATE TABLE current (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
time TIMESTAMP,
userid INT(30) NOT NULL,
compid INT(30) NOT NULL,
price FLOAT(15,2) NOT NULL,
quantity INT (10) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
//Create table for News!
$sql="CREATE TABLE news (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
time TIMESTAMP,
compid INT(30) NOT NULL,
content TEXT(500) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
// Registering the admin as the first user
$sql="INSERT INTO users (id, name, password, amount) VALUES (1,'admin','docwrocks',100000)";
if(mysqli_query($conn, $sql)){
echo "Admin registered successfully!<br/>";
}else{
echo "Error registering admin: " . mysqli_error($conn);
}
echo "<br/><br/>";
//creating table for logs
$sql="CREATE TABLE logs (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
time TIMESTAMP,
buyer INT(30) NOT NULL,
seller INT(30) NOT NULL,
compid INT(30) NOT NULL,
price INT(30) NOT NULL,
quantity INT(30) NOT NULL
)";
if (mysqli_query($conn, $sql)) {
echo "Table created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
echo "<br/><br/>";
?>