UsicSessionStorage.class.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. class UsicSessionStorage extends sfPDOSessionStorage
  3. {
  4. public function sessionWrite($id, $data)
  5. {
  6. // get table/column
  7. $db_table = $this->options['db_table'];
  8. $db_data_col = $this->options['db_data_col'];
  9. $db_id_col = $this->options['db_id_col'];
  10. $db_time_col = $this->options['db_time_col'];
  11. $db_addon_col = 'username';
  12. $value = sfContext::getInstance()->getUser()->hasAttribute('login') ?
  13. sfContext::getInstance()->getUser()->getAttribute('login') : 'NULL';
  14. $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = ?, '.$db_time_col.' = '.time().', '.$db_addon_col.' = '.$value.' WHERE '.$db_id_col.'= ?';
  15. try
  16. {
  17. $stmt = $this->db->prepare($sql);
  18. $stmt->bindParam(1, $data, PDO::PARAM_STR);
  19. $stmt->bindParam(2, $id, PDO::PARAM_STR);
  20. $stmt->execute();
  21. }
  22. catch (PDOException $e)
  23. {
  24. throw new sfDatabaseException(sprintf('PDOException was thrown when trying to manipulate session data. Message: %s', $e->getMessage()));
  25. }
  26. return true;
  27. }
  28. }