本文整理汇总了PHP中OC_DB::insertIfNotExist方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_DB::insertIfNotExist方法的具体用法?PHP OC_DB::insertIfNotExist怎么用?PHP OC_DB::insertIfNotExist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_DB
的用法示例。
在下文中一共展示了OC_DB::insertIfNotExist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertIfNotExist
/**
* Insert a row if a matching row doesn't exists.
* @param $table string The table name (will replace *PREFIX*) to perform the replace on.
* @param $input array
*
* The input array if in the form:
*
* array ( 'id' => array ( 'value' => 6,
* 'key' => true
* ),
* 'name' => array ('value' => 'Stoyan'),
* 'family' => array ('value' => 'Stefanov'),
* 'birth_date' => array ('value' => '1975-06-20')
* );
* @return bool
*
*/
public static function insertIfNotExist($table, $input)
{
return \OC_DB::insertIfNotExist($table, $input);
}
示例2: testinsertIfNotExistDontOverwrite
public function testinsertIfNotExistDontOverwrite()
{
$fullname = 'fullname test';
$uri = 'uri_1';
$carddata = 'This is a vCard';
// Normal test to have same known data inserted.
$query = OC_DB::prepare('INSERT INTO *PREFIX*' . $this->table2 . ' (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)');
$result = $query->execute(array($fullname, $uri, $carddata));
$this->assertTrue($result);
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*' . $this->table2 . ' WHERE `uri` = ?');
$result = $query->execute(array($uri));
$this->assertTrue($result);
$row = $result->fetchRow();
$this->assertArrayHasKey('carddata', $row);
$this->assertEqual($carddata, $row['carddata']);
$this->assertEqual('1', $result->numRows());
// Try to insert a new row
$result = OC_DB::insertIfNotExist('*PREFIX*' . $this->table2, array('fullname' => $fullname, 'uri' => $uri));
$this->assertTrue($result);
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*' . $this->table2 . ' WHERE `uri` = ?');
$result = $query->execute(array($uri));
$this->assertTrue($result);
$row = $result->fetchRow();
$this->assertArrayHasKey('carddata', $row);
// Test that previously inserted data isn't overwritten
$this->assertEqual($carddata, $row['carddata']);
// And that a new row hasn't been inserted.
$this->assertEqual('1', $result->numRows());
}