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; }
public static function ExecuteQuery($sql, $use_memcache = USE_MEMCACHE, $memcache_seconds = MEMCACHE_SECONDS, $memcache_custom_key = NULL) { $db = MDB::cursor(''); $db->SetConnection(DBConnectionManager::getProperConnection($sql)); return $db->query($sql, $use_memcache, $memcache_seconds, $memcache_custom_key); }