prepare($query); $stmt->bindParam(":username",$username); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = null; $query = null; // True if something is found, false if not return $result; } function retrieve_user_id(object $pdo, string $username) { $query = "SELECT id FROM users WHERE username = :username;"; // Prepare and check if user already exists $stmt = $pdo->prepare($query); $stmt->bindParam(":username",$username); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = null; $query = null; // True if something is found, false if not return $result["id"]; } function write_message(object $pdo, string $username, int $users_id, string $content) { $query = "INSERT INTO comments (username, users_id, content) VALUES (:username, :users_id, :content);"; $stmt = $pdo->prepare($query); $stmt->bindParam(':username',$username); $stmt->bindParam(':users_id',$users_id); $stmt->bindParam(':content',$content); $stmt->execute(); $stmt = null; $query = null; }