BxDolSessionQuery.php 1.6 KB

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