protected function do_set($data) { if (!isset($data['setting']) || !preg_match('/^[a-z_]+$/uis', $data['setting']) || !isset($data['value']) || !is_numeric($data['value'])) { return array('success' => false); } $setting = Database::get_field('setting', 'id', 'setting = ?', $data['setting']); if (empty($setting)) { return array('success' => false); } Database::replace('user_setting', array('id_user' => $this->user, 'id_setting' => $setting, 'value' => $data['value']), array('id_user', 'id_setting')); return array('success' => true); }
public function set($key, $value, $expire = null) { if (is_array($value) || is_object($value)) { $value = Database::pack($value); } if (empty($expire)) { $expire = DAY; } $expire = Database::unix_to_date(time() + $expire); $insert = array("key" => $key, "value" => $value, "expires" => $expire); Database::replace("cache", $insert, "key"); }
/** * 保存一个配置,支持批量设置 * * @param string/array $key 关键字 * @param fixed $value 值 * @param string $type 类型,长度32以内 * @return boolean */ public function set($key, $value, $type = '') { $db = new Database($this->database); $type = (string) $type; try { if (is_array($key)) { # 批量设置 $tr = $db->transaction(); $tr->start(); try { # 先尝试删除旧数据 $db->where('type', $type)->and_where_open(); foreach ($key as $k) { $db->or_where('key_md5', md5($k)); } $db->and_where_close()->delete($this->tablename); # 设置数据 foreach ($key as $i => $k) { $data = array('type' => $type, 'key_md5' => md5($k), 'key_name' => $k, 'value' => gzcompress(serialize($value[$i]), 9)); $db->values($data); } $db->columns(array('type', 'key_md5', 'key_name', 'value')); $db->insert($this->tablename); $tr->commit(); $this->clear_cache(); return true; } catch (Exception $e) { $tr->rollback(); return false; } } else { $data = array('type' => $type, 'key_md5' => md5($key), 'key_name' => $key, 'value' => gzcompress(serialize($value), 9)); $status = $db->replace($this->tablename, $data); } if ($status) { if (is_array($this->config)) { $this->config[$key] = $value; } $this->clear_cache(); return true; } else { return false; } } catch (Exception $e) { if (IS_DEBUG) { throw $e; } return false; } }
public function edit ($query) { if (!($this->test_rights($query))) { return; } $insert = array( 'type' => $query['type'], 'description_id' => $query['id'], 'pretty_text' => $query['text'], 'text' => Transform_Text::format($query['text']), ); Database::replace('description', $insert, array('type', 'description_id')); }
/** * Replace a row use primary key * * @param array $set * @return int */ public function replace($set = array()) { return $this->db->replace($this->_name, $set); }
/** * Add row to the redirect table if this is a redirect, remove otherwise. * * @param Database $dbw * @param $redirectTitle a title object pointing to the redirect target, * or NULL if this is not a redirect * @param bool $lastRevIsRedirect If given, will optimize adding and * removing rows in redirect table. * @return bool true on success, false on failure * @private */ function updateRedirectOn(&$dbw, $redirectTitle, $lastRevIsRedirect = null) { // Always update redirects (target link might have changed) // Update/Insert if we don't know if the last revision was a redirect or not // Delete if changing from redirect to non-redirect $isRedirect = !is_null($redirectTitle); if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) { wfProfileIn(__METHOD__); if ($isRedirect) { // This title is a redirect, Add/Update row in the redirect table $set = array('rd_namespace' => $redirectTitle->getNamespace(), 'rd_title' => $redirectTitle->getDBkey(), 'rd_from' => $this->getId()); $dbw->replace('redirect', array('rd_from'), $set, __METHOD__); } else { // This is not a redirect, remove row from redirect table $where = array('rd_from' => $this->getId()); $dbw->delete('redirect', $where, __METHOD__); } wfProfileOut(__METHOD__); return $dbw->affectedRows() != 0; } return true; }
protected function write_presense() { Database::replace('presense', array('id_game' => $this->id, 'id_user' => $this->user, 'time' => NULL), array('room', 'user')); }
public function set($section, $key, $value) { $this->data[$section][$key] = $value; Database::replace('setting', array( 'id_cookie' => $this->id, 'section' => $section, 'key' => $key, 'value' => $value ), array('id_cookie', 'section', 'key')); }