/** */ public function write($id, $session_data) { if (!$this->_db->isActive()) { $this->_db->reconnect(); $this->_db->beginDbTransaction(); } /* Check if session exists. */ try { $exists = $this->_db->selectValue(sprintf('SELECT 1 FROM %s WHERE session_id = ?', $this->_params['table']), array($id)); } catch (Horde_Db_Exception $e) { return false; } /* Update or insert session data. */ $values = array('session_data' => new Horde_Db_Value_Binary($session_data), 'session_lastmodified' => time()); try { if ($exists) { $this->_db->updateBlob($this->_params['table'], $values, array('session_id = ?', array($id))); } else { $this->_db->insertBlob($this->_params['table'], array_merge(array('session_id' => $id), $values)); } $this->_db->commitDbTransaction(); } catch (Horde_Db_Exception $e) { try { $this->_db->rollbackDbTransaction(); } catch (Horde_Db_Exception $e) { } return false; } return true; }
/** */ public function write($id, $session_data) { if (!$this->_db->isActive()) { $this->_db->reconnect(); $this->_db->beginDbTransaction(); } /* Check if session exists. */ try { $exists = $this->_db->selectValue(sprintf('SELECT 1 FROM %s WHERE session_id = ?', $this->_params['table']), array($id)); } catch (Horde_Db_Exception $e) { return false; } /* Update or insert session data. */ $session_data = new Horde_Db_Value_Binary($session_data); try { if ($exists) { $query = sprintf('UPDATE %s ' . 'SET session_data = ?, session_lastmodified = ? ' . 'WHERE session_id = ?', $this->_params['table']); $values = array($session_data, time(), $id); $this->_db->update($query, $values); } else { $query = sprintf('INSERT INTO %s ' . '(session_id, session_data, session_lastmodified) ' . 'VALUES (?, ?, ?)', $this->_params['table']); $values = array($id, $session_data, time()); $this->_db->insert($query, $values); } $this->_db->commitDbTransaction(); } catch (Horde_Db_Exception $e) { try { $this->_db->rollbackDbTransaction(); } catch (Horde_Db_Exception $e) { } return false; } return true; }
/** */ public function store($scope_ob) { if (!$this->_db->isActive()) { $this->_db->reconnect(); } $charset = $this->_db->getOption('charset'); // For each preference, check for an existing table row and // update it if it's there, or create a new one if it's not. foreach ($scope_ob->getDirty() as $name) { $value = $scope_ob->get($name); if (is_null($value)) { $this->remove($scope_ob->scope, $name); } else { $values = array($this->_params['user'], $name, $scope_ob->scope); // Does a row already exist for this preference? $query = 'SELECT 1 FROM ' . $this->_params['table'] . ' WHERE pref_uid = ? AND pref_name = ?' . ' AND pref_scope = ?'; try { $check = $this->_db->selectValue($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Prefs_Exception($e); } /* Driver has no support for storing locked status. */ $value = Horde_String::convertCharset($value, 'UTF-8', $charset); $value = new Horde_Db_Value_Binary($value); if (empty($check)) { // Insert a new row. $query = 'INSERT INTO ' . $this->_params['table'] . ' ' . '(pref_uid, pref_scope, pref_name, pref_value) VALUES' . '(?, ?, ?, ?)'; $values = array($this->_params['user'], $scope_ob->scope, $name, $value); try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Prefs_Exception($e); } } else { // Update the existing row. $query = 'UPDATE ' . $this->_params['table'] . ' SET pref_value = ?' . ' WHERE pref_uid = ?' . ' AND pref_name = ?' . ' AND pref_scope = ?'; $values = array($value, $this->_params['user'], $name, $scope_ob->scope); try { $this->_db->update($query, $values); } catch (Horde_Db_Exception $e) { throw new Horde_Prefs_Exception($e); } } } } }