BxDolKeyQuery.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolDb');
  10. /**
  11. * Database queries for BxDolKey object.
  12. * @see BxDolKey
  13. */
  14. class BxDolKeyQuery extends BxDolDb {
  15. public function __construct() {
  16. parent::__construct();
  17. }
  18. public function insert ($sKey, $sData, $iExpire) {
  19. $sQuery = $this->prepare("INSERT INTO `sys_keys` SET `key` = ?, `data` = ?, `expire` = ?", $sKey, $sData, time() + $iExpire);
  20. return $this->query($sQuery);
  21. }
  22. public function remove ($sKey) {
  23. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `key` = ?", $sKey);
  24. return $this->query($sQuery);
  25. }
  26. public function get ($sKey) {
  27. $sQuery = $this->prepare("SELECT `key` FROM `sys_keys` WHERE `key` = ?", $sKey);
  28. return $this->getOne($sQuery);
  29. }
  30. public function getData ($sKey) {
  31. $sQuery = $this->prepare("SELECT `data` FROM `sys_keys` WHERE `key` = ?", $sKey);
  32. return $this->getOne($sQuery);
  33. }
  34. public function prune () {
  35. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `expire` < ?", time());
  36. return $this->query($sQuery);
  37. }
  38. }
  39. /** @} */