本文整理汇总了PHP中Drupal\Core\Database\Connection::upsert方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::upsert方法的具体用法?PHP Connection::upsert怎么用?PHP Connection::upsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Database\Connection
的用法示例。
在下文中一共展示了Connection::upsert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSetMultiple
/**
* Stores multiple items in the persistent cache.
*
* @param array $items
* An array of cache items, keyed by cid.
*
* @see \Drupal\Core\Cache\CacheBackendInterface::setMultiple()
*/
protected function doSetMultiple(array $items)
{
$values = array();
foreach ($items as $cid => $item) {
$item += array('expire' => CacheBackendInterface::CACHE_PERMANENT, 'tags' => array());
assert('\\Drupal\\Component\\Assertion\\Inspector::assertAllStrings($item[\'tags\'])', 'Cache Tags must be strings.');
$item['tags'] = array_unique($item['tags']);
// Sort the cache tags so that they are stored consistently in the DB.
sort($item['tags']);
$fields = array('cid' => $this->normalizeCid($cid), 'expire' => $item['expire'], 'created' => round(microtime(TRUE), 3), 'tags' => implode(' ', $item['tags']), 'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']));
if (!is_string($item['data'])) {
$fields['data'] = serialize($item['data']);
$fields['serialized'] = 1;
} else {
$fields['data'] = $item['data'];
$fields['serialized'] = 0;
}
$values[] = $fields;
}
// Use an upsert query which is atomic and optimized for multiple-row
// merges.
$query = $this->connection->upsert($this->bin)->key('cid')->fields(array('cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized'));
foreach ($values as $fields) {
// Only pass the values since the order of $fields matches the order of
// the insert fields. This is a performance optimization to avoid
// unnecessary loops within the method.
$query->values(array_values($fields));
}
$query->execute();
}
示例2: save_sitemap
private function save_sitemap()
{
$this->db->upsert('custom_sitemap')->key(array('language_code', $this->language->getId()))->fields(array('language_code' => $this->language->getId(), 'sitemap_string' => $this->sitemap))->execute();
}