当前位置: 首页>>代码示例>>PHP>>正文


PHP Horde_Db_Adapter::insert方法代码示例

本文整理汇总了PHP中Horde_Db_Adapter::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Db_Adapter::insert方法的具体用法?PHP Horde_Db_Adapter::insert怎么用?PHP Horde_Db_Adapter::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Horde_Db_Adapter的用法示例。


在下文中一共展示了Horde_Db_Adapter::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ensureTypes

 /**
  * Ensure that an array of types exist in storage. Create any that don't,
  * return type_ids for all.
  *
  * @param mixed $types  An array of types or single type value. Values typed
  *                      as an integer are assumed to already be an type_id.
  *
  * @return array  An array of type_ids.
  * @throws Content_Exception
  */
 public function ensureTypes($types)
 {
     if (!is_array($types)) {
         $types = array($types);
     }
     $typeIds = array();
     $typeName = array();
     // Anything already typed as an integer is assumed to be a type id.
     foreach ($types as $typeIndex => $type) {
         if (is_int($type)) {
             $typeIds[$typeIndex] = $type;
         } else {
             $typeName[$type] = $typeIndex;
         }
     }
     try {
         // Get the ids for any types that already exist.
         if (count($typeName)) {
             $rows = $this->_db->selectAssoc('SELECT type_id, type_name FROM ' . $this->_t('types') . ' WHERE type_name IN (' . implode(',', array_map(array($this->_db, 'quoteString'), array_keys($typeName))) . ')');
             foreach ($rows as $id => $type) {
                 $typeIndex = $typeName[$type];
                 unset($typeName[$type]);
                 $typeIds[$typeIndex] = (int) $id;
             }
         }
         // Create any types that didn't already exist
         foreach ($typeName as $type => $typeIndex) {
             $typeIds[$typeIndex] = intval($this->_db->insert('INSERT INTO ' . $this->_t('types') . ' (type_name) VALUES (' . $this->_db->quoteString($type) . ')'));
         }
     } catch (Horde_Db_Exception $e) {
         throw new Content_Exception($e);
     }
     return $typeIds;
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:44,代码来源:Manager.php

示例2: ensureUsers

 /**
  * Ensure that an array of users exist in storage. Create any that don't,
  * return user_ids for all.
  *
  * @param array $users  An array of users. Values typed as an integer
  *                        are assumed to already be an user_id.
  *
  * @return array  An array of user_ids.
  */
 public function ensureUsers($users)
 {
     if (!is_array($users)) {
         $users = array($users);
     }
     $userIds = array();
     $userName = array();
     // Anything already typed as an integer is assumed to be a user id.
     foreach ($users as $userIndex => $user) {
         if (is_int($user)) {
             $userIds[$userIndex] = $user;
         } else {
             $userName[$user] = $userIndex;
         }
     }
     // Get the ids for any users that already exist.
     try {
         if (count($userName)) {
             $userName;
             $sql = 'SELECT user_id, user_name FROM ' . $this->_t('users') . ' WHERE user_name IN (' . implode(',', array_map(array($this, 'toDriver'), array_keys($userName))) . ')';
             foreach ($this->_db->selectAll($sql) as $row) {
                 $userIndex = $userName[$row['user_name']];
                 unset($userName[$row['user_name']]);
                 $userIds[$userIndex] = $row['user_id'];
             }
         }
         // Create any users that didn't already exist
         foreach ($userName as $user => $userIndex) {
             $userIds[$userIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('users') . ' (user_name) VALUES (' . $this->toDriver($user) . ')');
         }
     } catch (Horde_Db_Exception $e) {
         throw new Content_Exception($e);
     }
     return $userIds;
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:44,代码来源:Manager.php

示例3: setLocation

 /**
  * Set the location of the specified event _id
  *
  * @see Kronolith_Geo_Base#setLocation()
  * @throws Kronolith_Exception
  */
 public function setLocation($event_id, $point)
 {
     /* First make sure it doesn't already exist */
     $sql = 'SELECT COUNT(*) FROM kronolith_events_geo WHERE event_id = ?';
     try {
         $count = $this->_db->selectValue($sql, array($event_id));
     } catch (Horde_Db_Exception $e) {
         throw new Kronolith_Exception($e);
     }
     /* Do we actually have data? If not, see if we are deleting an
      * existing entry. */
     if ((empty($point['lat']) || empty($point['lon'])) && $count) {
         // Delete the record.
         $this->deleteLocation($event_id);
         return;
     } elseif (empty($point['lat']) || empty($point['lon'])) {
         return;
     }
     if (empty($point['zoom'])) {
         $point['zoom'] = 0;
     }
     /* INSERT or UPDATE */
     $params = array($point['lat'], $point['lon'], $point['zoom'], $event_id);
     try {
         if ($count) {
             $sql = 'UPDATE kronolith_events_geo SET event_lat = ?, event_lon = ?, event_zoom = ? WHERE event_id = ?';
             $this->_db->update($sql, $params);
         } else {
             $sql = 'INSERT into kronolith_events_geo (event_lat, event_lon, event_zoom, event_id) VALUES(?, ?, ?, ?)';
             $this->_db->insert($sql, $params);
         }
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Exception($e);
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:41,代码来源:Sql.php

示例4: addCollectionMap

 /**
  * Adds a collection ID map to the backend storage.
  *
  * @param string $internal   An internal collection ID.
  * @param string $external   An external collection ID.
  * @param string $interface  The collection's application.
  *
  * @throws Horde_Dav_Exception
  */
 public function addCollectionMap($internal, $external, $interface)
 {
     try {
         $this->_db->insert('INSERT INTO horde_dav_collections (id_internal, id_external, id_interface) ' . 'VALUES (?, ?, ?)', array($internal, $external, $interface));
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Dav_Exception($e);
     }
 }
开发者ID:horde,项目名称:horde,代码行数:17,代码来源:Sql.php

示例5: add

 /**
  * Serialize a task to the database
  * @param  Horde_Queue_Task $task  A task to serialize
  * @throws Horde_Queue_Exception
  */
 public function add(Horde_Queue_Task $task)
 {
     $values = array($this->_queue, serialize($task));
     $query = 'INSERT INTO horde_queue_tasks (task_queue, task_fields) VALUES(?, ?)';
     try {
         $this->_db->insert($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Queue_Exception($e);
     }
 }
开发者ID:horde,项目名称:horde,代码行数:15,代码来源:Db.php

示例6: _log

 /**
  */
 protected function _log($action, $message_id, $recipient, $success)
 {
     /* Build the SQL query. */
     $query = sprintf('INSERT INTO %s (sentmail_who, sentmail_ts, sentmail_messageid, sentmail_action, sentmail_recipient, sentmail_success) VALUES (?, ?, ?, ?, ?, ?)', $this->_params['table']);
     $values = array($GLOBALS['registry']->getAuth(), time(), $message_id, $action, $recipient, intval($success));
     /* Execute the query. */
     try {
         $this->_db->insert($query, $values);
     } catch (Horde_Db_Exception $e) {
     }
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:13,代码来源:Sql.php

示例7: 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. */
     $query = 'INSERT INTO ' . $this->_params['table'] . ' (cache_id, cache_timestamp, cache_expiration, cache_data)' . ' VALUES (?, ?, ?, ?)';
     $values = array($key, $timestamp, $expiration, $data);
     try {
         $this->_db->insert($query, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Cache_Exception($e);
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:28,代码来源:Sql.php

示例8: 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. */
     $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;
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:36,代码来源:Sql.php

示例9: _checkTags

 /**
  * Check if tags exists, optionally create them if they don't and return ids
  * for all that exist (including those that are optionally created).
  *
  * @param string|array $tags    The tag names to check.
  * @param boolean      $create  If true, create the tag in the tags table.
  *
  * @return array  A hash of tag_name => tag_id values.
  */
 protected function _checkTags($tags, $create = true)
 {
     if (empty($tags)) {
         return array();
     }
     if (!is_array($tags)) {
         $tags = is_int($tags) ? array($tags) : $this->splitTags($tags);
     }
     $tagIds = array();
     // Anything already typed as an integer is assumed to be a tag id.
     foreach ($tags as $tag) {
         if (is_int($tag)) {
             $tagIds[$tag] = $tag;
             continue;
         }
         // Don't attempt to tag with an empty value
         if (!strlen(trim($tag))) {
             continue;
         }
         // Get the ids for any tags that already exist.
         $sql = 'SELECT tag_id FROM ' . $this->_t('tags') . ' WHERE LOWER(tag_name) = LOWER(' . $this->toDriver($tag) . ')';
         if ($id = $this->_db->selectValue($sql)) {
             $tagIds[$tag] = (int) $id;
         } elseif ($create) {
             // Create any tags that didn't already exist
             $tagIds[$tag] = (int) $this->_db->insert('INSERT INTO ' . $this->_t('tags') . ' (tag_name) VALUES (' . $this->toDriver($tag) . ')');
         }
     }
     return $tagIds;
 }
开发者ID:horde,项目名称:horde,代码行数:39,代码来源:Tagger.php

示例10: addPermission

 /**
  * Adds a permission to the permissions system. The permission must first
  * be created with newPermission(), and have any initial users added to
  * it, before this function is called.
  *
  * @param Horde_Perms_Permission_Sql $perm  The perm object.
  *
  * @return integer  Permission ID in the database.
  * @throws Horde_Perms_Exception
  */
 public function addPermission(Horde_Perms_Permission $perm)
 {
     $name = $perm->getName();
     if (empty($name)) {
         throw new Horde_Perms_Exception('Permission name must be non-empty.');
     }
     $this->_cache->expire('perm_sql_' . $this->_cacheVersion . $name);
     $this->_cache->expire('perm_sql_exists_' . $this->_cacheVersion . $name);
     // remove root from the name
     $root = Horde_Perms::ROOT . ':';
     if (substr($name, 0, strlen($root)) == $root) {
         $name = substr($name, strlen($root));
     }
     // build parents
     $parents = '';
     if (($pos = strrpos($name, ':')) !== false) {
         $parent_name = substr($name, 0, $pos);
         $query = 'SELECT perm_id, perm_parents FROM ' . $this->_params['table'] . ' WHERE perm_name = ?';
         $result = $this->_db->selectOne($query, array($parent_name));
         if (empty($result)) {
             throw new Horde_Perms_Exception(Horde_Perms_Translation::t("Trying to create sub permission of non-existent parent permission. Create parent permission(s) first."));
         }
         $parents = $result['perm_parents'] . ':' . $result['perm_id'];
     }
     $query = 'INSERT INTO ' . $this->_params['table'] . ' (perm_name, perm_parents) VALUES (?, ?)';
     try {
         $id = $this->_db->insert($query, array($name, $parents));
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Perms_Exception($e);
     }
     $perm->setId($id);
     $perm->save();
     return $id;
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:44,代码来源:Sql.php

示例11: saveSyncCache

 /**
  * Save the provided sync_cache.
  *
  * @param array $cache   The cache to save.
  * @param string $devid  The device id.
  * @param string $user   The user id.
  * @param array $dirty   An array of dirty properties. @since 2.9.0
  *
  * @throws Horde_ActiveSync_Exception
  */
 public function saveSyncCache(array $cache, $devid, $user, array $dirty = null)
 {
     $cache['timestamp'] = strval($cache['timestamp']);
     $sql = 'SELECT count(*) FROM ' . $this->_syncCacheTable . ' WHERE cache_devid = ? AND cache_user = ?';
     try {
         $have = $this->_db->selectValue($sql, array($devid, $user));
     } catch (Horde_Db_Exception $e) {
         $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage()));
         throw new Horde_ActiveSync_Exception($e);
     }
     $cache = serialize($cache);
     if ($have) {
         $this->_logger->info(sprintf('[%s] Replacing SYNC_CACHE entry for user %s and device %s: %s', $this->_procid, $user, $devid, $cache));
         $sql = 'UPDATE ' . $this->_syncCacheTable . ' SET cache_data = ? WHERE cache_devid = ? AND cache_user = ?';
         try {
             $this->_db->update($sql, array($cache, $devid, $user));
         } catch (Horde_Db_Exception $e) {
             $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage()));
             throw new Horde_ActiveSync_Exception($e);
         }
     } else {
         $this->_logger->info(sprintf('[%s] Adding new SYNC_CACHE entry for user %s and device %s: %s', $this->_procid, $user, $devid, $cache));
         $sql = 'INSERT INTO ' . $this->_syncCacheTable . ' (cache_data, cache_devid, cache_user) VALUES (?, ?, ?)';
         try {
             $this->_db->insert($sql, array($cache, $devid, $user));
         } catch (Horde_Db_Exception $e) {
             $this->_logger->err(sprintf('[%s] %s', $this->_procid, $e->getMessage()));
             throw new Horde_ActiveSync_Exception($e);
         }
     }
 }
开发者ID:platolin,项目名称:horde,代码行数:41,代码来源:Sql.php

示例12: setLock

 /**
  * Sets a lock on the requested principal and returns the generated lock
  * ID.
  *
  * @see Horde_Lock_Base::setLock()
  */
 public function setLock($requestor, $scope, $principal, $lifetime = 1, $type = Horde_Lock::TYPE_SHARED)
 {
     $oldlocks = $this->getLocks($scope, $principal, $type == Horde_Lock::TYPE_SHARED ? Horde_Lock::TYPE_EXCLUSIVE : null);
     if (count($oldlocks) != 0) {
         // A lock exists.  Deny the new request.
         if ($this->_logger) {
             $this->_logger->log(sprintf('Lock requested for %s denied due to existing lock.', $principal), 'NOTICE');
         }
         return false;
     }
     $lockid = (string) new Horde_Support_Uuid();
     $now = time();
     $expiration = $lifetime == Horde_Lock::PERMANENT ? Horde_Lock::PERMANENT : $now + $lifetime;
     $sql = 'INSERT INTO ' . $this->_params['table'] . ' (lock_id, lock_owner, lock_scope, lock_principal, lock_origin_timestamp, lock_update_timestamp, lock_expiry_timestamp, lock_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
     $values = array($lockid, $requestor, $scope, $principal, $now, $now, $expiration, $type);
     try {
         $this->_db->insert($sql, $values);
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Lock_Exception($e);
     }
     if ($this->_logger) {
         $this->_logger->log(sprintf('Lock %s set successfully by %s in scope %s on "%s"', $lockid, $requestor, $scope, $principal), 'DEBUG');
     }
     return $lockid;
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:31,代码来源:Sql.php

示例13: ensureObjects

 /**
  * Ensure that an array of objects exist in storage. Create any that don't,
  * return object_ids for all. All objects in the $objects array must be
  * of the same content type.
  *
  * @param mixed $objects  An array of objects (or single obejct value).
  *                        Values typed as an integer are assumed to already
  *                        be an object_id.
  * @param mixed $type     Either a string type_name or integer type_id
  *
  * @return array  An array of object_ids.
  */
 public function ensureObjects($objects, $type)
 {
     if (!is_array($objects)) {
         $objects = array($objects);
     }
     $objectIds = array();
     $objectName = array();
     $type = current($this->_typeManager->ensureTypes($type));
     // Anything already typed as an integer is assumed to be an object id.
     foreach ($objects as $objectIndex => $object) {
         if (is_int($object)) {
             $objectIds[$objectIndex] = $object;
         } else {
             $objectName[$object] = $objectIndex;
         }
     }
     // Get the ids for any objects that already exist.
     try {
         if (count($objectName)) {
             $rows = $this->_db->selectAll('SELECT object_id, object_name FROM ' . $this->_t('objects') . ' WHERE object_name IN (' . implode(',', array_map(array($this->_db, 'quoteString'), array_keys($objectName))) . ') AND type_id = ' . $type);
             foreach ($rows as $row) {
                 $objectIndex = $objectName[$row['object_name']];
                 unset($objectName[$row['object_name']]);
                 $objectIds[$objectIndex] = $row['object_id'];
             }
         }
         // Create any objects that didn't already exist
         foreach ($objectName as $object => $objectIndex) {
             $objectIds[$objectIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('objects') . ' (object_name, type_id) VALUES (' . $this->_db->quoteString($object) . ', ' . $type . ')');
         }
     } catch (Horde_Db_Exception $e) {
         throw new Content_Exception($e);
     }
     return $objectIds;
 }
开发者ID:Gomez,项目名称:horde,代码行数:47,代码来源:Manager.php

示例14: updateClientSettings

 /**
  * @TODO
  *
  * @param <type> $clientID
  * @param <type> $enterDescription
  * @param string $exportID
  * @return <type>
  */
 public function updateClientSettings($clientID, $enterDescription = 1, $exportID = null)
 {
     if (empty($exportID)) {
         $exportID = null;
     }
     $sql = 'SELECT clientjob_id FROM hermes_clientjobs WHERE clientjob_id = ?';
     $values = array($clientID);
     if ($this->_db->selectValue($sql, $values) !== $clientID) {
         $sql = 'INSERT INTO hermes_clientjobs (clientjob_id,' . ' clientjob_enterdescription, clientjob_exportid)' . ' VALUES (?, ?, ?)';
         $values = array($clientID, (int) $enterDescription, $this->_convertToDriver($exportID));
         try {
             return $this->_db->insert($sql, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Hermes_Exception($e);
         }
     } else {
         $sql = 'UPDATE hermes_clientjobs SET' . ' clientjob_exportid = ?, clientjob_enterdescription = ?' . ' WHERE clientjob_id = ?';
         $values = array($this->_convertToDriver($exportID), (int) $enterDescription, $clientID);
         try {
             return $this->_db->update($sql, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Hermes_Exception($e);
         }
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:33,代码来源:Sql.php

示例15: addUser

 /**
  * Add a user to a group.
  *
  * @param mixed $gid    A group ID.
  * @param string $user  A user name.
  *
  * @throws Horde_Group_Exception
  */
 public function addUser($gid, $user)
 {
     try {
         $this->_db->insert('INSERT INTO horde_groups_members (group_uid, user_uid) VALUES (?, ?)', array($gid, $user));
     } catch (Horde_Db_Exception $e) {
         throw new Horde_Group_Exception($e);
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:16,代码来源:Sql.php


注:本文中的Horde_Db_Adapter::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。