示例#1
0
 /**
  * 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
0
文件: db.php 项目: Combustible/core
 /**
  * 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);
 }