public static function find($sql_query) { if (self::get_connection()) { AmyLogger::logn('SQL query: ', $sql_query); return pg_query($sql_query); } return false; }
public static function find($sql_query) { if (self::get_connection()) { $sql_query = str_replace(' amy.', ' amy_', $sql_query); AmyLogger::logn('SQL query: ', $sql_query); if ('development' == $GLOBALS['_AMY_CONF']['environment']) { return mysqli_query(self::$connection, $sql_query); } else { return @mysqli_query(self::$connection, $sql_query); } } return false; }
public function create($userId = 1) { AmyLogger::logn('Creating session for:', $userId); if (!is_numeric($userId)) { AmyLogger::logn("Invalid user ID specified: `{$userId}'"); throw new Exception("Invalid user ID specified: `{$userId}'"); } try { $this->authorize(); if ($userId == $this->authInfo['user_id']) { AmyLogger::logn("Already authorized, renewing.", $this->authInfo); if (time() + self::RENEW_BEFORE_EXPIRATION < $this->authInfo['expired_at']) { AmyLogger::logn("Not necessary to renew yet."); // not renewing until one hour before expiration to avoid overhead return $this; } // let's renew it $this->authInfo['expired_at'] = time() + self::EXPIRES_AFTER_SECONDS; $this->save(); AmyLogger::logn("Renewed successfully"); return $this; } } catch (Exception $e) { } $this->authInfo['user_id'] = $userId; $this->authInfo['expired_at'] = time() + self::EXPIRES_AFTER_SECONDS; $this->authInfo['token'] = $this->generate_hash(); $this->save(); AmyLogger::logn('Setting cookie for newly created session: ', $this->authInfo); setcookie('amy_token', $this->authInfo['token'], 0, '/'); return $this; }