public static function SearchFull($query, $maxRows) { $conn = RPDatabase::createConnection(); $query = "%{$query}%"; $statement = $conn->prepare("SELECT\n `Room`.`Title`,\n `Room`.`ID`,\n `Room`.`Time_Created`,\n `Room`.`IP`,\n `Room`.`ID`,\n `Room`.`Number`,\n COUNT(*) AS `Found_Count`\n FROM `Message` LEFT JOIN `Room` ON (\n `Room`.`Number` = `Message`.`Room_Number`\n ) WHERE `Message`.`Content` LIKE ?\n GROUP BY `Room`.`ID`\n ORDER BY `Found_Count` DESC LIMIT {$maxRows}"); $statement->execute(array($query)); return $statement->fetchAll(); }
public static function GetRoom($id) { if (!Room::IsValidID($id)) { throw new Exception("Malformed Room ID: '{$id}'", Room::INVALID_ROOM_ID_EXCEPTION); } $conn = RPDatabase::createConnection(); if (!Room::IDExists($id, $conn)) { throw new Exception("Room '{$id}' does not exist.", Room::ROOM_NOT_FOUND_EXCEPTION); } $statement = $conn->prepare(' SELECT `Number`, `Title`, `Description`, (SELECT COUNT(*) FROM `Character` WHERE `Character`.`Room_Number` = `Room`.`Number`) AS `CharacterCount`, (SELECT COUNT(*) FROM `Message` WHERE `Message`.`Room_Number` = `Room`.`Number`) AS `MessageCount` FROM `Room` WHERE `ID` = ? '); $statement->execute(array($id)); if ($statement->rowCount() == 0) { throw new Exception("Room '{$id}' expected but not found."); } $row = $statement->fetch(); return new Room($conn, $id, $row['Number'], $row['Title'], $row['Description'], +$row['CharacterCount'], +$row['MessageCount']); }