| 70 | | // delete the record associated with this id |
|---|
| 71 | | $sql = 'DELETE FROM '.$db_table.' WHERE '.$db_time_col.' < '.(time() - $lifetime); |
|---|
| 72 | | |
|---|
| 73 | | if (!@mysql_query($sql, $this->db->getResource())) |
|---|
| 74 | | { |
|---|
| 75 | | throw new sfDatabaseException(sprintf('sfMySQLSessionStorage cannot delete old sessions (%s).', mysql_error())); |
|---|
| | 71 | // delete the record older than the authorised session life time |
|---|
| | 72 | $lifetime = $this->db_escape($lifetime); // We never know... |
|---|
| | 73 | $sql = "DELETE FROM $db_table 'WHERE $db_time_col + INTERVAL $lifetime SECOND < NOW()"; |
|---|
| | 74 | |
|---|
| | 75 | if (!$this->db_query($sql)) |
|---|
| | 76 | { |
|---|
| | 77 | throw new sfDatabaseException(sprintf('% cannot delete old sessions (%s).', get_class($this), mysql_error())); |
|---|
| 116 | | $sql = 'INSERT INTO '.$db_table.' ('.$db_id_col.', '.$db_data_col.', '.$db_time_col.') VALUES (\''.$id.'\', \'\', '.time().')'; |
|---|
| 117 | | |
|---|
| 118 | | if (@mysql_query($sql, $this->db->getResource())) |
|---|
| | 118 | $sql = "INSERT INTO $db_table ($db_id_col, $db_data_col, $db_time_col) VALUES ('$id', '', NOW())"; |
|---|
| | 119 | |
|---|
| | 120 | if ($this->db_query($sql)) |
|---|
| 147 | | $id = mysql_real_escape_string($id, $this->db->getResource()); |
|---|
| 148 | | $data = mysql_real_escape_string($data, $this->db->getResource()); |
|---|
| 149 | | |
|---|
| 150 | | // delete the record associated with this id |
|---|
| 151 | | $sql = 'UPDATE '.$db_table.' SET '.$db_data_col.' = \''.$data.'\', '.$db_time_col.' = '.time().' WHERE '.$db_id_col.' = \''.$id.'\''; |
|---|
| 152 | | |
|---|
| 153 | | if (@mysql_query($sql, $this->db->getResource())) |
|---|
| | 149 | $id = $this->db_escape($id); |
|---|
| | 150 | $data = $this->db_escape($data); |
|---|
| | 151 | |
|---|
| | 152 | // update the record associated with this id |
|---|
| | 153 | $sql = "UPDATE $db_table SET $db_data_col='$data', $db_time_col=NOW() WHERE $db_id_col='$id'"; |
|---|
| | 154 | |
|---|
| | 155 | if ($this->db_query($sql)) |
|---|
| 159 | | throw new sfDatabaseException(sprintf('sfMySQLSessionStorage cannot write session data for id "%s" (%s).', $id, mysql_error())); |
|---|
| | 161 | throw new sfDatabaseException(sprintf('% cannot write session data for id "%s" (%s).', get_class($this), $id, mysql_error())); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | /*! |
|---|
| | 165 | * Execute an SQL Query |
|---|
| | 166 | * |
|---|
| | 167 | * @param $query (string) The query to execute |
|---|
| | 168 | * @return (mixed) The result of the query |
|---|
| | 169 | */ |
|---|
| | 170 | protected function db_query($query) |
|---|
| | 171 | { |
|---|
| | 172 | return @mysql_query($query, $this->db->getResource()); |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | /*! |
|---|
| | 176 | * Escape a string before using it in a query statement |
|---|
| | 177 | * |
|---|
| | 178 | * @param $string (string) The string to escape |
|---|
| | 179 | * @return (string) The escaped string |
|---|
| | 180 | */ |
|---|
| | 181 | protected function db_escape($string) |
|---|
| | 182 | { |
|---|
| | 183 | return mysql_real_escape_string($string, $this->db->getResource()); |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | /*! |
|---|
| | 187 | * Count the rows in a query result |
|---|
| | 188 | * |
|---|
| | 189 | * @param $result (resource) Result of a query |
|---|
| | 190 | * @return (int) Number of rows |
|---|
| | 191 | */ |
|---|
| | 192 | protected function db_num_rows($result) |
|---|
| | 193 | { |
|---|
| | 194 | return mysql_num_rows($result); |
|---|
| | 195 | } |
|---|
| | 196 | |
|---|
| | 197 | /*! |
|---|
| | 198 | * Extract a row from a query result set |
|---|
| | 199 | * |
|---|
| | 200 | * @param $result (resource) Result of a query |
|---|
| | 201 | * @return (array) Extracted row as an indexed array |
|---|
| | 202 | */ |
|---|
| | 203 | protected function db_fetch_row($result) |
|---|
| | 204 | { |
|---|
| | 205 | return mysql_fetch_row($result); |
|---|