BxDolSessionQuery.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @package Dolphin Core
  4. * @copyright Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  5. * @license CC-BY - http://creativecommons.org/licenses/by/3.0/
  6. */
  7. defined('BX_DOL') or die('hack attempt');
  8. bx_import('BxDolDb');
  9. /**
  10. * @see BxDolSession
  11. */
  12. class BxDolSessionQuery extends BxDolDb {
  13. var $sTable;
  14. function BxDolSessionQuery() {
  15. parent::BxDolDb();
  16. $this->sTable = 'sys_sessions';
  17. }
  18. function getTableName() {
  19. return $this->sTable;
  20. }
  21. function exists($sId) {
  22. $sSql = $this->prepare("SELECT `id`, `user_id`, `data` FROM `" . $this->sTable . "` WHERE `id`=? LIMIT 1", $sId);
  23. $aSession = $this->getRow($sSql);
  24. return !empty($aSession) ? $aSession : false;
  25. }
  26. function save($sId, $aSet) {
  27. $sSetClause = $this->prepare("`id`=?", $sId);
  28. foreach($aSet as $sKey => $sValue)
  29. $sSetClause .= $this->prepare(", `" . $sKey . "`=?", $sValue);
  30. $sSetClause .= ", `date`=UNIX_TIMESTAMP()";
  31. return (int)$this->query("REPLACE INTO `" . $this->sTable . "` SET " . $sSetClause) > 0;
  32. }
  33. function delete($sId) {
  34. $sSql = $this->prepare("DELETE FROM `" . $this->sTable . "` WHERE `id`=? LIMIT 1", $sId);
  35. return (int)$this->query($sSql) > 0;
  36. }
  37. function deleteExpired() {
  38. $sSql = $this->prepare("DELETE FROM `" . $this->sTable . "` WHERE `date` < (UNIX_TIMESTAMP() - ?)", BX_DOL_SESSION_LIFETIME);
  39. $iRet = (int)$this->query($sSql);
  40. $this->query("OPTIMIZE TABLE `" . $this->sTable . "`");
  41. return $iRet;
  42. }
  43. }