-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
64 lines (52 loc) · 2.02 KB
/
setup.php
File metadata and controls
64 lines (52 loc) · 2.02 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Cloud Computing</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="margin-top:10px;">
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<?php
function pg_connection_string_from_database_url(){
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" .substr($path,1);
}
$db = pg_connect(pg_connection_string_from_database_url());
if(!$db){
echo "Error : Unable to open database \n";
}else{
echo '<div class="alert alert-info" style="text-align:center;padding-top:10px;">';
echo '<strong>Opened database successfully</strong>';
echo '</div>';
}
$sql = "CREATE TABLE IF NOT EXISTS MyAccounts (username CHAR(10) PRIMARY KEY NOT NULL,
password CHAR(50))";
echo '<div class="alert alert-warning" style="text-align:center;padding-top:10px;">';
print "$sql";
echo '</div>';
$ret = pg_query($db, $sql);
if(!$ret){
echo pg_last_error($db);
}else{
echo '<div class="alert alert-primary" style="text-align:center;padding-top:10px;">';
echo '<strong>Table created successfully</strong>';
echo '</div>';
}
pg_close($db);
?>
<br>
<a class="btn btn-sm btn-danger" href="index.php" role="button">Quay lại trang chủ</a>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"></div>
</div>
</div>
</body>
</html>