-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatedb.php
More file actions
188 lines (157 loc) · 5.42 KB
/
createdb.php
File metadata and controls
188 lines (157 loc) · 5.42 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
$mysqli = mysqli_connect('localhost', 'root', '');
if (!$mysqli) {
die('Could not connect: ' . mysqli_error());
}
if ($mysqli->select_db('cms')){
echo 'suessful connect to cms database';
}
else {
$sql = 'CREATE DATABASE cms';
if ($mysqli->query($sql)) {
echo "Database cms created successfully\n";
} else {
echo 'Error creating database: ' . mysqli_error($mysqli) . "\n";
}
}
$mysqli->select_db('cms');
// sql code to create category table into cms database
$query = "CREATE TABLE IF NOT EXISTS `category`(
`cat_id` int(11) NOT NULL AUTO_INCREMENT,
`category_name` varchar(35) NOT NULL,
PRIMARY KEY(cat_id));";
if($mysqli->query($query)){
echo "Category table has been successfully created!";
}else{
echo "Error creating category table:" . mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO category VALUES('', 'Garden')");
if($query){
echo "Data is successfully inserted!";
}
else
{
echo "Some problem occured!";
}
$query = $mysqli->query("INSERT INTO category VALUES('', 'Electronics')");
if($query){
echo "Data successfully inserted!";
}
else
{
echo "Some problem occured!";
}
//sql code to create products table into cms database
$query = "CREATE TABLE IF NOT EXISTS `products`(
`id` int(11) NOT NULL AUTO_INCREMENT,
`product_code` varchar(60) NOT NULL,
`product_img_name` varchar(60) NOT NULL,
`product_name` varchar(60) NOT NULL,
`product_desc` tinytext NOT NULL,
`price` decimal(10,2) NOT NULL,
`stock` text NOT NULL,
-- `file_size` int(11) NOT NULL,
`uploaded_date` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `product_code` (`product_code`),
cat_id int(11) NOT NULL)";
if($mysqli->query($query)){
echo "Products table has been successfully created!";
}else{
echo "Error creating products table:" . mysqli_error($mysqli);
}
// $FileSize = $_FILES['mFile']["size"];
$uploaded_date = date("Y-m-d H:i:s");
$query = $mysqli->query("INSERT INTO products VALUES('', 'PD1001', 'box1.jpg', 'Dummy Image 1', 'This is a Dummy Image 1.', '200', '10', '$uploaded_date', '2')");
if($query){
echo "Product PD1001 is successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO products VALUES('', 'PD1002', 'box2.jpg', 'Dummy Image 2', 'This is a Dummy Image 2.', '350', '15', '$uploaded_date', '1')");
if($query){
echo "Product PD1002 is successfully inserted!";
}
else
{
echo "Some problem occured!";
}
$query = $mysqli->query("INSERT INTO products VALUES('', 'PD1003', 'box3.jpg', 'Dummy Image 3', 'This is a Dummy Image 3.', '240', '5', '$uploaded_date', '2')");
if($query){
echo "Product PD1002 is successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
//sql code to create customer table
$query = "CREATE TABLE IF NOT EXISTS `customer`(
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(10) NOT NULL,
`fname` varchar(40) NOT NULL,
`mname` varchar(40) NOT NULL,
`lname` varchar(40) NOT NULL,
`phone` varchar(35) NOT NULL,
`email` varchar(45) NOT NULL,
`addressline1` varchar(50) NOT NULL,
`addressline2` varchar(50) NOT NULL,
`town` varchar(45) NOT NULL,
`city` varchar(45) NOT NULL,
`postcode`varchar(10) NOT NULL,
`country` varchar(40) NOT NULL,
`orderdate` date NOT NULL,
PRIMARY KEY(`customer_id`));";
if($mysqli->query($query)){
echo "Customer table has been successfully created!";
}else{
echo "Error creating customer table:" . mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO customer VALUES('', 'Mr', 'John', '', 'Cooper', '07588589868', 'john@hotmail.com', '155 Viking', '', 'London', 'South London', 'SK223GG', 'United Kingdom', '$uploaded_date')");
if($query){
echo "Data is successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO customer VALUES('', 'Mrs', 'Sita', '', 'Smith', '07538689868', 'sita@gmail.com', '12 Halewood', '', 'Bracknell', 'Berkshire', 'RG215OP', 'United Kingdom', '$uploaded_date')");
if($query){
echo "Data successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
// sql code to create order details table
$query = "CREATE TABLE IF NOT EXISTS `order_details`(
`orderdetails_id` int(11) NOT NULL AUTO_INCREMENT,
`quantity` SMALLINT NOT NULL,
`price` decimal(10,2) NOT NULL,
`subtotal` decimal(10,2) NOT NULL,
PRIMARY KEY(orderdetails_id),
`product_id` int(11) NOT NULL,
`customer_id` int(11) NOT NULL);";
if($mysqli->query($query)){
echo "order_details table has been successfully created!";
}else{
echo "Error creating products table:" . mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO order_details VALUES('', '2', '200', '400', '1', '1')");
if($query){
echo "Data is successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
$query = $mysqli->query("INSERT INTO order_details VALUES('', '3', '350', '1050', '2', '2')");
if($query){
echo "Data successfully inserted!";
}
else
{
echo "Some problem occured!". mysqli_error($mysqli);
}
?>