|
@@ -0,0 +1,57 @@
|
|
1
|
+<?PHP
|
|
2
|
+
|
|
3
|
+class EveDB {
|
|
4
|
+
|
|
5
|
+ private $pdo;
|
|
6
|
+
|
|
7
|
+ private $handlers;
|
|
8
|
+
|
|
9
|
+ public function __construct($connection = null) {
|
|
10
|
+ $this->pdo = new PDO($connection == null ? 'sqlite:' . dirname(__FILE__) . '/inc110-sqlite3-v1.db' : $connection);
|
|
11
|
+
|
|
12
|
+ $this->handlers = array(
|
|
13
|
+ 'items' => new ItemsTableHandler($this->pdo),
|
|
14
|
+ );
|
|
15
|
+ }
|
|
16
|
+
|
|
17
|
+ public function __get($type) {
|
|
18
|
+ return isset($this->handlers[$type]) ? $this->handlers[$type] : null;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+abstract class BaseHandler {
|
|
24
|
+
|
|
25
|
+ protected $pdo;
|
|
26
|
+
|
|
27
|
+ public function __construct($pdo) {
|
|
28
|
+ $this->pdo = $pdo;
|
|
29
|
+ $this->initStatements();
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ protected abstract function initStatements();
|
|
33
|
+
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+class ItemsTableHandler extends BaseHandler {
|
|
37
|
+
|
|
38
|
+ private $getByIdSmt;
|
|
39
|
+
|
|
40
|
+ protected function initStatements() {
|
|
41
|
+ $columns = 'categoryName, typeID, typeName, invTypes.description';
|
|
42
|
+ $joins = 'JOIN invGroups ON (invGroups.groupID = invTypes.groupID) JOIN invCategories ON (invGroups.categoryID = invCategories.categoryID)';
|
|
43
|
+ $skeleton = 'SELECT ' . $columns . ' FROM invTypes ' . $joins . ' WHERE';
|
|
44
|
+
|
|
45
|
+ $this->getByIdSmt = $this->pdo->prepare($skeleton . ' typeID = :id');
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ public function getById($id) {
|
|
49
|
+ $this->getByIdSmt->execute(array(':id' => $id));
|
|
50
|
+ return $this->getByIdSmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+class Ship {}
|
|
56
|
+
|
|
57
|
+?>
|