本文整理匯總了PHP中OCP\DB::insertIfNotExist方法的典型用法代碼示例。如果您正苦於以下問題:PHP DB::insertIfNotExist方法的具體用法?PHP DB::insertIfNotExist怎麽用?PHP DB::insertIfNotExist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OCP\DB
的用法示例。
在下文中一共展示了DB::insertIfNotExist方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testInsertIfNotExistsViolatingThrows
/**
* @dataProvider insertIfNotExistsViolatingThrows
* @expectedException \Doctrine\DBAL\Exception\UniqueConstraintViolationException
*
* @param array $compareKeys
*/
public function testInsertIfNotExistsViolatingThrows($compareKeys)
{
$result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID()));
$this->assertEquals(1, $result);
$result = \OCP\DB::insertIfNotExist('*PREFIX*' . $this->table5, array('storage' => 1, 'path_hash' => md5('welcome.txt'), 'etag' => $this->getUniqueID()), $compareKeys);
$this->assertEquals(0, $result);
}
示例2: tagAs
/**
* Creates a tag/object relation.
*
* @param int $objid The id of the object
* @param string $tag The id or name of the tag
* @return boolean Returns false on error.
*/
public function tagAs($objid, $tag)
{
if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
if ($tag === '') {
\OCP\Util::writeLog('core', __METHOD__ . ', Cannot add an empty tag', \OCP\Util::DEBUG);
return false;
}
if (!$this->hasTag($tag)) {
$this->add($tag);
}
$tagId = $this->getTagId($tag);
} else {
$tagId = $tag;
}
try {
\OCP\DB::insertIfNotExist(self::RELATION_TABLE, array('objid' => $objid, 'categoryid' => $tagId, 'type' => $this->type));
} catch (\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
return true;
}