123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- class sfPostgreSQLSessionStorage extends sfDatabaseSessionStorage
- {
-
- public function sessionDestroy($id)
- {
-
- $db_table = $this->options['db_table'];
- $db_id_col = $this->options['db_id_col'];
-
- $id = addslashes($id);
-
- $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\'';
- if (@pg_query($this->db, $sql))
- {
- return true;
- }
-
- throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot destroy session id "%s".', $id));
- }
-
- public function sessionGC($lifetime)
- {
-
- $db_table = $this->options['db_table'];
- $db_time_col = $this->options['db_time_col'];
-
- $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime);
- if (!@pg_query($this->db, $sql))
- {
- throw new sfDatabaseException('sfPostgreSQLSessionStorage cannot delete old sessions.');
- }
- return true;
- }
-
- public function sessionRead($id)
- {
-
- $db_table = $this->options['db_table'];
- $db_data_col = $this->options['db_data_col'];
- $db_id_col = $this->options['db_id_col'];
- $db_time_col = $this->options['db_time_col'];
-
- $id = addslashes($id);
-
- $sql = 'SELECT '.$db_data_col.' FROM '.$db_table.' WHERE '.$db_id_col.' = \''.$id.'\'';
- $result = @pg_query($this->db, $sql);
- if ($result != false && @pg_num_rows($result) == 1)
- {
-
- $data = pg_fetch_row($result);
- return $data[0];
- }
- else
- {
-
- $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', '.$db_data_col.', '.$db_time_col.') VALUES (\''.$id.'\', \'\', '.time().')';
- if (@pg_query($this->db, $sql))
- {
- return '';
- }
-
- throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot create new record for id "%s".', $id));
- }
- }
-
- public function sessionWrite($id, $data)
- {
-
- $db_table = $this->options['db_table'];
- $db_data_col = $this->options['db_data_col'];
- $db_id_col = $this->options['db_id_col'];
- $db_time_col = $this->options['db_time_col'];
-
- $id = addslashes($id);
- $data = addslashes($data);
-
- $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = \''.$data.'\', '.$db_time_col.' = '.time().' WHERE '.$db_id_col.' = \''.$id.'\'';
- if (@pg_query($this->db, $sql))
- {
- return true;
- }
-
- throw new sfDatabaseException(sprintf('sfPostgreSQLSessionStorage cannot write session data for id "%s".', $id));
- }
- }
|