本文整理汇总了PHP中Horde_Db_Adapter::insertBlob方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Db_Adapter::insertBlob方法的具体用法?PHP Horde_Db_Adapter::insertBlob怎么用?PHP Horde_Db_Adapter::insertBlob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Db_Adapter
的用法示例。
在下文中一共展示了Horde_Db_Adapter::insertBlob方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
*/
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;
}
示例2: save
/**
* Save the current state to storage
*
* @throws Horde_ActiveSync_Exception
*/
public function save()
{
// Prepare state and pending data
if ($this->_type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) {
$data = isset($this->_folder) ? serialize($this->_folder) : '';
$pending = '';
} elseif ($this->_type == Horde_ActiveSync::REQUEST_TYPE_SYNC) {
$pending = isset($this->_changes) ? serialize(array_values($this->_changes)) : '';
$data = isset($this->_folder) ? serialize($this->_folder) : '';
} else {
$pending = '';
$data = '';
}
// If we are setting the first synckey iteration, do not save the
// syncstamp/mod, otherwise we will never get the initial set of data.
$params = array('sync_key' => $this->_syncKey, 'sync_data' => new Horde_Db_Value_Binary($data), 'sync_devid' => $this->_deviceInfo->id, 'sync_mod' => self::getSyncKeyCounter($this->_syncKey) == 1 ? 0 : $this->_thisSyncStamp, 'sync_folderid' => !empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC, 'sync_user' => $this->_deviceInfo->user, 'sync_pending' => $pending, 'sync_timestamp' => time());
$this->_logger->info(sprintf('[%s] Saving state: %s', $this->_procid, serialize(array($params['sync_key'], $params['sync_data'], $params['sync_devid'], $params['sync_mod'], $params['sync_folderid'], $params['sync_user'], count($this->_changes), time()))));
try {
$this->_db->insertBlob($this->_syncStateTable, $params);
} catch (Horde_Db_Exception $e) {
// Might exist already if the last sync attempt failed.
$this->_logger->notice(sprintf('[%s] Previous request processing for synckey %s failed to be accepted by the client, removing previous state and trying again.', $this->_procid, $this->_syncKey));
$this->_db->delete('DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?', array($this->_syncKey));
$this->_db->insertBlob($this->_syncStateTable, $params);
}
}
示例3: set
/**
*/
public function set($key, $data, $lifetime = 0)
{
$okey = $key;
$key = hash('md5', $key);
$timestamp = time();
// 0 lifetime indicates the object should not be GC'd.
$expiration = $lifetime === 0 ? 0 : $lifetime + $timestamp;
if ($this->_logger) {
$this->_logger->log(sprintf('Cache set: %s (Id %s set at %d expires at %d)', $okey, $key, $timestamp, $expiration), 'DEBUG');
}
// Remove any old cache data and prevent duplicate keys
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE cache_id = ?';
$values = array($key);
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
}
/* Build SQL query. */
$values = array('cache_id' => $key, 'cache_timestamp' => $timestamp, 'cache_expiration' => $expiration, 'cache_data' => new Horde_Db_Value_Binary($data));
try {
$this->_db->insertBlob($this->_params['table'], $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Cache_Exception($e);
}
}
示例4: setMetaData
/**
*/
public function setMetaData($mailbox, $data)
{
if (!($uid = $this->_getUid($mailbox))) {
$uid = $this->_createUid($mailbox);
}
$query = sprintf('SELECT field FROM %s where messageid = ?', self::MD_TABLE);
$values = array($uid);
try {
$fields = $this->_db->selectValues($query, $values);
} catch (Horde_Db_Exception $e) {
return;
}
foreach ($data as $key => $val) {
$val = new Horde_Db_Value_Binary($key == 'uidvalid' ? $val : serialize($val));
if (in_array($key, $fields)) {
/* Update */
try {
$this->_db->updateBlob(self::MD_TABLE, array('data' => $val), array('field = ? AND messageid = ?', array($key, $uid)));
} catch (Horde_Db_Exception $e) {
}
} else {
/* Insert */
try {
$this->_db->insertBlob(self::MD_TABLE, array('data' => $val, 'field' => $key, 'messageid' => $uid));
} catch (Horde_Db_Exception $e) {
}
}
}
}
示例5: _add
/**
* Adds the specified object to the SQL database.
*
* @param array $attributes The attribute values of the contact.
* @param array $blob_fields Fields that represent binary data.
* @param array $date_fields Fields that represent dates. @since 4.2.0
*
* @throws Turba_Exception
*/
protected function _add(array $attributes, array $blob_fields = array(), array $date_fields = array())
{
list($fields, $values) = $this->_prepareWrite($attributes, $blob_fields, $date_fields);
try {
$this->_db->insertBlob($this->_params['table'], array_combine($fields, $values));
} catch (Horde_Db_Exception $e) {
throw new Turba_Exception(_("Server error when adding data."));
}
}
示例6: _add
/**
* Adds an alarm hash to the backend.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
protected function _add(array $alarm)
{
$values = array('alarm_id' => $alarm['id'], 'alarm_uid' => isset($alarm['user']) ? $alarm['user'] : '', 'alarm_start' => $alarm['start']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), 'alarm_end' => empty($alarm['end']) ? null : $alarm['end']->setTimezone('UTC')->format(Horde_Date::DATE_DEFAULT), 'alarm_methods' => serialize($alarm['methods']), 'alarm_params' => new Horde_Db_Value_Text(base64_encode(serialize($alarm['params']))), 'alarm_title' => $this->_toDriver($alarm['title']), 'alarm_text' => empty($alarm['text']) ? null : new Horde_Db_Value_Text($this->_toDriver($alarm['text'])), 'alarm_snooze' => null, 'alarm_instanceid' => empty($alarm['instanceid']) ? null : $alarm['instanceid']);
try {
$this->_db->insertBlob($this->_params['table'], $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception(Horde_Alarm_Translation::t("Server error when querying database."));
}
}
示例7: insertBlob
/**
* Inserts a row including BLOBs into a table.
*
* @since Horde_Db 2.1.0
*
* @param string $table The table name.
* @param array $fields A hash of column names and values. BLOB columns
* must be provided as Horde_Db_Value_Binary
* objects.
* @param string $pk The primary key column.
* @param integer $idValue The primary key value. This parameter is
* required if the primary key is inserted
* manually.
*
* @return integer Last inserted ID.
* @throws Horde_Db_Exception
*/
public function insertBlob($table, $fields, $pk = null, $idValue = null)
{
$result = $this->_write->insertBlob($table, $fields, $pk, $idValue);
$this->_lastQuery = $this->_write->getLastQuery();
// Once doing writes, keep using the write backend even for reads
// at least during the same request, to help against stale data.
$this->_read = $this->_write;
return $result;
}
示例8: store
/**
*/
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.
$values = array('pref_uid' => $this->_params['user'], 'pref_scope' => $scope_ob->scope, 'pref_name' => $name, 'pref_value' => $value);
try {
$this->_db->insertBlob($this->_params['table'], $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
} else {
// Update the existing row.
try {
$this->_db->updateBlob($this->_params['table'], array('pref_value' => $value), array('pref_uid = ? AND pref_name = ? AND pref_scope = ?', array($this->_params['user'], $name, $scope_ob->scope)));
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
}
}