-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.php
More file actions
93 lines (78 loc) · 2.19 KB
/
Copy pathmanager.php
File metadata and controls
93 lines (78 loc) · 2.19 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
<?php
$serverName = "localhost";
$username = "root";
$password = "";
$dbName = "H";
$fileName = "setup/products.csv";
$success = true;
// Create connection
$connection = new mysqli($serverName, $username, $password);
// Create database
$connection->query("CREATE DATABASE $dbName");
// Connect to database
$connection->select_db($dbName);
// Create table
$connection->query("
CREATE TABLE products (
itemID INT AUTO_INCREMENT,
name VARCHAR(150),
brand VARCHAR(20),
category VARCHAR(20),
price VARCHAR(10),
inventory INT,
discount INT,
description TEXT (5000),
PRIMARY KEY (itemID)
)"
);
// Makes autoincrements start at 1001
$connection->query("ALTER TABLE products AUTO_INCREMENT=1001;");
// Open csv file, "r" = read only
$products = fopen($fileName, "r");
$x = 0;
while (($c = fgetcsv($products, 0, ",")) != FALSE) {
$x++;
$insertData = "INSERT INTO products (name,brand,category,price,inventory,discount, description)
VALUES ('$c[0]','$c[1]','$c[2]','$c[3]','$c[4]','$c[5]','$c[6]')";
$result = mysqli_query($connection, $insertData);
if (empty($result)) {
echo "Problem in Importing CSV Data on Product #$x";
echo "<br>";
$success = false;
}
}
$connection->query("
CREATE TABLE shoppingcart (
itemID INT,
quantity INT
)
");
$connection->query("
CREATE TABLE customers (
customerID INT AUTO_INCREMENT,
customerName VARCHAR(50),
addressLine1 VARCHAR(100),
addressLine2 VARCHAR(100),
city VARCHAR (50),
province VARCHAR(50),
postalCode VARCHAR (10),
telephoneNumber VARCHAR(10),
PRIMARY KEY(customerID)
)
");
$connection->query("
CREATE TABLE orders (
itemID SMALLINT,
quantity SMALLINT,
orderID INT,
customerID INT
)
");
if ($success) {
echo "Database is set up properly!";
} else {
echo "The above errors appeared when setting up database.";
}
fclose($products);
$connection->close();
?>