BxDolSessionQuery.php 1.6 KB

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