-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_database.php
51 lines (40 loc) · 1021 Bytes
/
create_database.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
<?php
$username = "root";
$password = "root";
$servername = "localhost";
$database = "myDB";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DROP TABLE sports";
$conn->query($sql);
//create table
$sql = "CREATE TABLE sports (
GameID integer NOT NULL AUTO_INCREMENT,
Sport varchar(32),
Level varchar(16),
GameDate Date,
Homescore integer,
Awayscore integer,
PRIMARY KEY (GameID)
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>