1
0

BxDolKeyQuery.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for BxDolKey object.
  11. * @see BxDolKey
  12. */
  13. class BxDolKeyQuery extends BxDolDb
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. }
  19. public function insert ($sKey, $sData, $iExpire)
  20. {
  21. $sQuery = $this->prepare("INSERT INTO `sys_keys` SET `key` = ?, `data` = ?, `expire` = ?", $sKey, $sData, time() + $iExpire);
  22. return $this->query($sQuery);
  23. }
  24. public function remove ($sKey)
  25. {
  26. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `key` = ?", $sKey);
  27. return $this->query($sQuery);
  28. }
  29. public function get ($sKey)
  30. {
  31. $sQuery = $this->prepare("SELECT `key` FROM `sys_keys` WHERE `key` = ?", $sKey);
  32. return $this->getOne($sQuery);
  33. }
  34. public function getData ($sKey)
  35. {
  36. $sQuery = $this->prepare("SELECT `data` FROM `sys_keys` WHERE `key` = ?", $sKey);
  37. return $this->getOne($sQuery);
  38. }
  39. public function prune ()
  40. {
  41. $sQuery = $this->prepare("DELETE FROM `sys_keys` WHERE `expire` < ?", time());
  42. return $this->query($sQuery);
  43. }
  44. }
  45. /** @} */