public function SaveProfileOptions() { PhxMemcache::delete("nsfw_settings_{$this->session->user->id}"); $m = Model::Factory("user_data"); if (isset($this->post->show_nsfw)) { $m->show_nsfw = (int) $this->post->show_nsfw; } $m->where("user_id='{$this->session->user->id}'"); $m->update(); PhxMemcache::set("nsfw_settings_{$this->session->user->id}", $this->post->show_nsfw, 0); header("Content-type:application/json;charset=utf-8"); $o = new stdClass(); $o->status = 1; die(json_encode($o)); }
public function query($sql, $use_memcache, $seconds, $memcache_custom_key) { $connection = DBConnectionManager::getProperConnection($sql); $this->SetConnection($connection); #Hack to cache only the SELECTS $isSelectQuery = preg_match('/^SELECT/i', $sql); if ($use_memcache && !$isSelectQuery or USE_MEMCACHE == false) { $use_memcache = false; } if ($use_memcache) { $memcache_key = is_null($memcache_custom_key) ? md5($sql) : $memcache_custom_key; if ($data = PhxMemcache::get($memcache_key)) { return $data; } else { $data = mysqli_query($this->conn, $sql); $this->log($sql, $data); $data = $this->fetchObject($data); PhxMemcache::set($memcache_key, $data, $seconds); } } else { $data = mysqli_query($this->conn, $sql); if ($isSelectQuery) { $data = $this->fetchObject($data); } $this->log($sql, $data); if (preg_match('/^CALL/i', $sql)) { $this->switch_to_next_result = true; } } if (!$data && mysqli_error($this->conn) != '') { $logger = Logger::getInstance('txt'); $logger->file = 'query_error_.' . date('ymd') . '.txt'; $logger->message(mysqli_error($this->conn) . "\n\n" . print_r($sql, true)); } return $data; }