-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbn.php
61 lines (51 loc) · 1.43 KB
/
nbn.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
<?php
/*
Database backend for NBN-domain lookup
Recives a GET request (ie, localhost/nbn.php?postcode=1234)
And returns the status of that area as defined by NBNCo.
*/
$mysqli = new mysqli('host','user','password','nbn');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT status,commencment,completion FROM lookup WHERE postcode=?")) {
/* bind parameters for markers */
$stmt->bind_param("s", $_GET['postcode']);
/* execute query */
$stmt->execute();
/*needed to get num rows*/
$stmt->store_result();
/* if this is 0 then return "no work"*/
$num_of_rows = $stmt->num_rows;
/* bind result variables */
$stmt->bind_result($status,$commence,$complete);
/* fetch value */
$stmt->fetch();
if ($num_of_rows > 0)
{
if ($commence == "")
{
printf("%s\n", $status);
}
elseif ($complete == "")
{
printf("%s started %s",$status,$commence);
}
else
{
printf("%s started %s due to complete %s",$status,$commence,$complete);
}
}
elseif ($num_of_rows == 0)
{
print "Work has not commenced and is not currently planned to commence";
}
/* status statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>