Unfinished website for an EVE-online corporation
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

evedb.class.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?PHP
  2. require_once(dirname(dirname(__FILE__)) . '/model/ship.php');
  3. class EveDB {
  4. private $pdo;
  5. private $handlers;
  6. public function __construct($connection = null) {
  7. $this->pdo = new PDO($connection == null ? 'sqlite:' . dirname(__FILE__) . '/inc110-sqlite3-v1.db' : $connection);
  8. $this->handlers = array(
  9. 'items' => new ItemsTableHandler($this->pdo),
  10. );
  11. }
  12. public function __get($type) {
  13. return isset($this->handlers[$type]) ? $this->handlers[$type] : null;
  14. }
  15. }
  16. abstract class BaseHandler {
  17. protected $pdo;
  18. public function __construct($pdo) {
  19. $this->pdo = $pdo;
  20. $this->initStatements();
  21. }
  22. protected abstract function initStatements();
  23. }
  24. class ItemsTableHandler extends BaseHandler {
  25. private $getByIdSmt;
  26. protected function initStatements() {
  27. $columns = 'categoryName, typeID, typeName, invTypes.description';
  28. $joins = 'JOIN invGroups ON (invGroups.groupID = invTypes.groupID) JOIN invCategories ON (invGroups.categoryID = invCategories.categoryID)';
  29. $skeleton = 'SELECT ' . $columns . ' FROM invTypes ' . $joins . ' WHERE';
  30. $this->getByIdSmt = $this->pdo->prepare($skeleton . ' typeID = :id');
  31. }
  32. public function getById($id) {
  33. $this->getByIdSmt->execute(array(':id' => $id));
  34. return $this->getByIdSmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE);
  35. }
  36. }
  37. ?>