BxDolSessionQuery.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 TridentCore Trident Core
  7. * @{
  8. */
  9. bx_import('BxDolDb');
  10. /**
  11. * @see BxDolSession
  12. */
  13. class BxDolSessionQuery extends BxDolDb
  14. {
  15. protected $sTable;
  16. function __construct()
  17. {
  18. parent::__construct();
  19. $this->sTable = 'sys_sessions';
  20. }
  21. function getTableName()
  22. {
  23. return $this->sTable;
  24. }
  25. function exists($sId)
  26. {
  27. $sSql = $this->prepare("SELECT `id`, `user_id`, `data` FROM `" . $this->sTable . "` WHERE `id`=? LIMIT 1", $sId);
  28. $aSession = $this->getRow($sSql);
  29. return !empty($aSession) ? $aSession : false;
  30. }
  31. function save($sId, $aSet)
  32. {
  33. $sSetClause = $this->prepare("`id`=?", $sId);
  34. foreach($aSet as $sKey => $sValue)
  35. $sSetClause .= $this->prepare(", `" . $sKey . "`=?", $sValue);
  36. $sSetClause .= ", `date`=UNIX_TIMESTAMP()";
  37. return (int)$this->query("REPLACE INTO `" . $this->sTable . "` SET " . $sSetClause) > 0;
  38. }
  39. function delete($sId)
  40. {
  41. $sSql = $this->prepare("DELETE FROM `" . $this->sTable . "` WHERE `id`=? LIMIT 1", $sId);
  42. return (int)$this->query($sSql) > 0;
  43. }
  44. function deleteExpired()
  45. {
  46. $sSql = $this->prepare("DELETE FROM `" . $this->sTable . "` WHERE `date` < (UNIX_TIMESTAMP() - ?)", BX_DOL_SESSION_LIFETIME);
  47. $iRet = (int)$this->query($sSql);
  48. $this->query("OPTIMIZE TABLE `" . $this->sTable . "`");
  49. return $iRet;
  50. }
  51. }
  52. /** @} */