Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("../init.php");
- /**
- * This file returns account information. It's designed to be run from an
- * AJAX request, hence it been rather standalone.
- *
- * @param int $_GET["userID"]
- * @param int $_GET["mode"]
- *
- * $_GET["mode"]:
- * unset/unrecognised: both
- * 1: username only
- * 2: profileImg only
- *
- * Echoes out JSON.
- */
- try {
- new Database();
- // throw new PDOException("some error...");
- if (!isset($_GET["id"]))
- throw new Exception("ID is unset.");
- if (!isset($_GET["mode"])) {
- $stmt = Database::$db->prepare("SELECT username, profileImg FROM users WHERE id = :id");
- } else {
- switch ($_GET["mode"]) {
- case "1":
- $stmt = Database::$db->prepare("SELECT username FROM users WHERE id = :id");
- break;
- case "2":
- $stmt = Database::$db->prepare("SELECT profileImg FROM users WHERE id = :id");
- break;
- default:
- $stmt = Database::$db->prepare("SELECT username, profileImg FROM users WHERE id = :id");
- }
- }
- $stmt->execute(array("id" => $_GET["id"]));
- if ($stmt->rowCount() < 1)
- throw new Exception("A user with that ID was not found.");
- $json = json_encode($stmt->fetch(PDO::FETCH_ASSOC));
- if (!$json)
- throw new Exception("Return value could not be encoded into JSON.");
- echo $json;
- } catch (Exception $e) {
- echo json_encode(array("errorMsg" => get_class($e) . ": " . $e->getMessage()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement