本文整理匯總了PHP中OC\DB\Connection::insertIfNotExist方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::insertIfNotExist方法的具體用法?PHP Connection::insertIfNotExist怎麽用?PHP Connection::insertIfNotExist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類OC\DB\Connection
的用法示例。
在下文中一共展示了Connection::insertIfNotExist方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setValue
/**
* Sets a value. If the key did not exist before it will be created.
*
* @param string $app app
* @param string $key key
* @param string $value value
* @return void
*/
public function setValue($app, $key, $value)
{
$inserted = false;
// Does the key exist? no: insert, yes: update.
if (!$this->hasKey($app, $key)) {
$inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', ['appid' => $app, 'configkey' => $key, 'configvalue' => $value], ['appid', 'configkey']);
}
if (!$inserted) {
$oldValue = $this->getValue($app, $key);
if ($oldValue === strval($value)) {
return;
}
$data = array('configvalue' => $value);
$where = array('appid' => $app, 'configkey' => $key);
$this->conn->update('*PREFIX*appconfig', $data, $where);
}
if (!isset($this->cache[$app])) {
$this->cache[$app] = array();
}
if (is_array($this->apps) and array_search($app, $this->apps) === false) {
$this->apps[$app] = $app;
}
$this->cache[$app][$key] = $value;
}
示例2: insertIfNotExist
/**
* Insert a row if a matching row doesn't exists.
* @param string $table The table to insert into in the form '*PREFIX*tableName'
* @param array $input An array of fieldname/value pairs
* @return boolean number of updated rows
*/
public static function insertIfNotExist($table, $input)
{
self::connect();
return self::$connection->insertIfNotExist($table, $input);
}