-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.php
84 lines (74 loc) · 1.67 KB
/
app.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
<?php
include_once ("Connection.php");
$connection = new Connection();
createDB();
createTable();
insertData();
checkData();
dropDB();
function createDB(){
global $connection;
if($connection->setConnection('db','root','1234')){
if($connection->createDatabase('php_simple')){
print("true\n");
}else{
print("false\n");
}
}else{
print("false\n");
}
}
function createTable(){
global $connection;
$sql = "CREATE TABLE Employee (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL
)";
if($connection->selectDatabase('php_simple')){
if($connection->executeQuery($sql)){
print("true\n");
}else{
print("false\n");
}
}
else{
print("false\n");
}
}
function insertData(){
global $connection;
$sql = "INSERT INTO Employee (firstname, lastname)
VALUES ('John', 'Peterson')";
if($connection->selectDatabase('php_simple')){
if($connection->executeQuery($sql)){
print("true\n");
}
else{
print("false\n");
}
}
else{
print("false\n");
}
}
function checkData(){
global $connection;
if($connection->checkTable('Employee')){
print("true\n");
}
else{
print("false\n");
}
}
function dropDB(){
global $connection;
$sql = "DROP DATABASE php_simple";
if($connection->executeQuery($sql)){
print("true\n");
}
else{
print("false\n");
}
$connection->closeConnection();
}