Skip to content

Commit 933c207

Browse files
lbernailmaur1th
authored andcommitted
Sample php site
1 parent 921085d commit 933c207

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

phpsite/application.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
database = "mydb"
2+
dbhost = "mydb.cwe2ozwnuq5m.eu-west-1.rds.amazonaws.com"
3+
dbuser = "admin"
4+
dbpassword = "password"

phpsite/index.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
$table="mytable";
4+
5+
$hello="Hello world";
6+
$date = date('Y/m/d H:i:s');
7+
8+
$serverIP=$_SERVER['SERVER_ADDR'];
9+
10+
$sql="select hello from $table";
11+
$props = parse_ini_file("application.properties");
12+
13+
$conn = new mysqli($props['dbhost'], $props['dbuser'], $props['dbpassword'],$props['database']);
14+
// check connection
15+
if ($conn->connect_error) {
16+
echo 'Unable to connect to DB. Error: ' . $conn->connect_error;
17+
exit();
18+
}
19+
20+
$rs=$conn->query($sql);
21+
22+
if($rs === false) {
23+
echo "Unable to retrieve data: ".$conn->error;
24+
} else {
25+
$rs->data_seek(0);
26+
$row = $rs->fetch_row();
27+
}
28+
29+
?>
30+
31+
<html>
32+
<body>
33+
<h2>
34+
<?php echo $hello; ?>
35+
</h2>
36+
<p>The time is <?php echo $date; ?></p>
37+
<p>Server IP is <?php echo $serverIP; ?></p>
38+
<p>Content of the first table row: <?php echo $row[0]; ?></p>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)