-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRDSHelper.php
executable file
·98 lines (83 loc) · 3.22 KB
/
RDSHelper.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace TestPlugin\DataClasses\ServiceHelpers {
use TestPlugin\PDOHelper;
use TestPlugin\SQLLoader;
use TestPlugin\UtilityFunctions;
use TestPlugin\PDOConnectionInfo;
use TestPlugin\PDOHelperContainer;
/**
* A class that helps connect and use an Amazon Web Services RDS instance
* */
class RDSHelper implements PDOHelperContainer {
private $rdsConnection;
public function getPDOHelper():PDOHelper {return $this->rdsConnection;}
private $rdsConfig;
public function getPDOConnectionInfo():PDOConnectionInfo {return $this->rdsConfig;}
public function __construct(array $rdsConfig, SQLLoader $loader) {
$this->rdsConfig = PDOConnectionInfo::fromAssocArray($rdsConfig);
if(!$this->verifyConfig() ) {
throw new \Exception("The RDS Configuration is missing required fields.");
} else {
$this->initConnection($loader);
}
}
public function verifyConfig() : bool {
return ($this->rdsConfig === NULL) ? false : $this->rdsConfig->verify();
}
private function initConnection(SQLLoader $loader) {
$this->rdsConnection = new PDOHelper($this->rdsConfig, $loader);
$this->rdsConnection->connect();
}
/**
* Lists all database rows, building a basic HTML table.
* <b>This method is NOT complete, and simply returns a static table.</b>
*/
public function listAllDBRows() {
$allRowData = $this->selectAllFromDB();
$tableHtml = "
<table class=\"table table-bordered\">
<thead>
<tr>
<th>DB</th>
<th>Column1</th>
</tr>
</thead>
<tbody>
";
//$this->rdsPDOConnection
/*
foreach ($allBucketContents as $bucketName => $bucketContents) {
if(count($bucketContents) > 0) {
foreach ($bucketContents as $object) {//this is paginated, hence a loop needed
$tableHtml .= "<tr>
<td>".$bucketName."</td>
<td><a href='https://".$bucketName.".s3.amazonaws.com/".$object['Key']."'>".$object['Key']."</a></td>
</tr>";
}
} else {
$tableHtml .= "
<td> No files </td>
";
}
}
*/
$tableHtml .= "
</tbody>
</table>
";
echo $tableHtml;
}
/**
* Selects all rows from all tables in the database.
* <b>This method is NOT complete, and simply returns an empty associative array</b>
*/
public function selectAllFromDB() {
$allRows = [];
return $allRows;
}
function __destruct() {
$this->rdsConnection = NULL;
$this->rdsConfig = NULL;
}
}
}