-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTable.php
More file actions
43 lines (36 loc) · 1.13 KB
/
Copy pathcreateTable.php
File metadata and controls
43 lines (36 loc) · 1.13 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
<?php
// Database configuration
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ClothingStore_db"; // Required name
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create Database if it doesn't exist
$sqlCreateDB = "CREATE DATABASE IF NOT EXISTS $dbname";
$conn->query($sqlCreateDB);
$conn->select_db($dbname);
// SQL to create tblUser
$tableUser = "CREATE TABLE IF NOT EXISTS tblUser (
userID INT(11) AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(255) NOT NULL,
status VARCHAR(20) DEFAULT 'Pending'
)";
// SQL to create tblAdmin
$tableAdmin = "CREATE TABLE IF NOT EXISTS tblAdmin (
adminID INT(11) AUTO_INCREMENT PRIMARY KEY,
adminName VARCHAR(50) NOT NULL,
adminPassword VARCHAR(255) NOT NULL
)";
// Execute table creation
$conn->query($tableUser);
$conn->query($tableAdmin);
echo "Database and Tables initialized successfully.";
$conn->close();
?>