Unfinished website for an EVE-online corporation
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

evedb.class.php 1.2KB

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